Basic MySQL Commands

Basic MySQL operations

mysql -u {user_name} -p{password} -h {host_name}

You can simply run the mysql client and type the password, but this form lets you log in from any shell. You will probably use it more often. If you changed the DB port, add -P {port} (the default is 3306).

SHOW DATABASES;
USE {db_name};
SHOW TABLES;

Inspecting definitions

DESC {db_name};

DESC is shorthand for DESCRIBE.

SHOW TABLE STATUS LIKE '{table_name}';

The LIKE clause accepts wildcards such as %, so you can search flexibly—not only exact table names.

SHOW VARIABLES STATUS LIKE '{parameter_name}';
SHOW GLOBAL STATUS LIKE '{parameter_name}';
SHOW PROCEDURE STATUS;
SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';
mysqldump -u {user_name} -p{password} -h {host_name} -B {database_name} > {output_file_name}
mysqldump -u {user_name} -p{password} -h {host_name} -A > {output_file_name}
mysql -u {user_name} -p{password} -h {host_name} < {output_file_name}