Exploit-DB updates

Sunday, July 3, 2011

Getting started with MySQL Shell

Okay so I've just recently started getting into a web dev and what not, but I thought I'd make a quick how-to for getting started with MySQL on the linux platform.

First off, make sure you've got a LAMP setup (Linux Apache MySQL & PHP). If you're using a debian based distro you can download them with the repositories like so;

sudo apt-get install apache2 mysql-server apache-mod-php5 php5-mysql

After those install, you'll want to set a password for your MySQL account (MySQL SHOULD be running, but it can be started like so; /etc/init.d/mysql start).

mysqladmin -u root password ThePassword


Now you should set your password set, you can login to MySQL and get to the fun stuff.

mysql -u root -p

You'll be prompted for your pass, after you log in you can start interacting with the DBase. 

/*
Alternatively you can log in without a password, as there is none by default. then could could issue the query like this;

mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Yourpassword');

 */

If for wanted to view the existing DBases you can issue the following command;

mysql> show databases;

Now to create a DBase you can simply do this;

mysql> create database MonsantosArsenal;

Now if we wanted to move to that DBase we could do the following;

mysql> use MonsantosArsenal;

Now, what's a DBase without tables?

mysql> create table Weapons(
         WepID int,
         Weapon varchar(50)
          );

And that'll create a table named Weapons in the Database MonsantosArsenal. You can now begin adding columns with the insert command, but first I want to point out that you can set a integer to automatically increment by 1 like this;


mysql> create table Weapons(
         WepID int not null auto_increment,
         Weapon varchar(50)
          );

mysql> insert into MonsantosArsenal (Weapon)
          VALUES("Genetically modified food");

You now have a table with a column named "Weapon" that has the value we chose to insert. I hope this helps get you started with the mysql shell.

No comments:

Post a Comment