11 Useful MySQL Commands for Quick Reference

July 3, 2008

Here are a few useful MySQL commands for common routine work related with database management. I keep these statements on my desk as a quick reference guide.

I am not a MySQL database administrator. Nor do I write MySQL statements every day. But I do deal with this amazing (and free!) database server every now and then. As I go out of touch with MySQL for quite sometime, I tend to forget several key commands. So, I have made a list of some very useful MySQL commands and I keep them with me as ready reference guide. These commands help you saving time when you know what you want to do but don’t know how to do it! I would suggest that you take a note of these commands and keep them printed on your desk.

If you are using MySQL Server and have to work through the command prompt, following are a few very handy statements:

mysql> SHOW TABLES;

It shows the list of tables that exist in the database currently in use.

mysql> DESCRIBE table_name;

Returns the structure of the table mentioned.

mysql> SHOW TABLE STATUS LIKE "table_name";

Returns more information about the table. Returned information includes engine type, number of rows, data length, index length, checksum, creation time etc.

mysql> SHOW CREATE TABLE table_name;

Returns the CREATE statement that was used to create the table specified. It is useful in case we want to create the same table again -or with a slight modification.

The above command, mysqldump, also dumps a table into a file but in addition it also includes the table drop and table creation statements in the file.

mysql> SOURCE file_name;

If you want to execute a set of SQL commands in one go -then write them into a text file (called a SQL script file and is generally stored with a .sql extension) and use the above command to execute them all. If you are on the shell prompt you can use the following command to do the same:

shell> mysql database_name < file_name

As I said this is a ready reference list for me, I keep on adding new statements to this list as I come across during my work. I hope these were useful for you. Please let me know if you have more such MySQL commands. We can grow this list together.

Related Articles for More Information:

Lalit Kumar is the Principal Author and Founder of TechWelkin. He is a web explorer and he enjoys finding useful information on the Internet. He loves to put things together to create a bigger solution. Lalit is passionate about technology, languages and literature. You can contact Lalit via email (techwelkin [at] gmail [dot] com) or Facebook (facebook.com/techwelkin).