MySQL cheat sheet

Selecting a database:

mysql> USE database;

Listing databases:


Listing tables in a db:


Describing the format of a table:

mysql> DESCRIBE table;

Creating a database:

mysql> CREATE DATABASE db_name;

Creating a table:

mysql> CREATE TABLE table_name (field1_name TYPE(SIZE), field2_name TYPE(SIZE)); Ex: mysql> CREATE TABLE pet (name VARCHAR(20), sex CHAR(1), birth DATE);

Resetting MySQL root password

To reset MySQL password, you need to have root access to the machine. After logging in as root, start by shutting down MySQL:

$ /sbin/service mysqld stop

Verify that all mysql processes have been shut down.

$ ps waux | grep 'mysql'

For all processes that are listed

$ kill -9

Find your mysqld_safe.

$ locate mysqld_safe

My mysqld_safe is installed at /usr/bin/mysqld_safe. Yours might be elsewhere. Start MySQL without the grant tables.

Setting up virtual lamp stack on microsoft windows

Oracle's VirtualBox is a very solid and stable virtual machine but it isn't the simplest to work with. So I abandoned it a week after I started working with. Recently, I had to return. Why? Vagrant. It is a fantastic virtual machine workflow system. It is amazingly easy to use and deals with VirtualBox for you. On top of that there are many excellent stack available for free download from the Internet. Following is how I setup my LAMP stack.