MySQL Admin

If you do any web development either with PHP, JSP, and/or Ruby on Rails you most likely will use MySQL. The following is all that you need to know to get started with MySQL. I am currently using MySQL 4.1.14. To install MySQL just unzipped it to the c:\ drive. To start the MySQL server cd to the bin directory and execute the following:

bin>mysqld

Once the server has started you can connect using the command line tool mysql. From a command prompt, just type the following:

bin>mysql

Once logged on you can view the available databases by running this command:

show databases;

To create a new database use the create command as in:

create database <database_name>;

Of course, you will need to replace <database_name> with an appropriate name. To start using a specific database from those available enter the following command:

use <database_name>;

It is nice to list all the defined tables in a database schema, to do so in MySQL enter this next command:

show tables;

And if you are like me and suffer from development amnesia, you will fail to remember those hardly ever used table column names. Well, the next command describes a given table’s metadata such as column name and type:

describe <table_name>;

Once you have created your database and database tables, you will most likely need to create a user for that database schema. To create a user, execute the following:

grant all on <database_name>.* to
<user_name>@localhost identified by '<password>';

And when you are done you can stop the server by executing the following:

bin>mysqladmin -u root shutdown

There is a lot more to MySQL than this short tutorial. Like Oracle and other databases, MySQL provides import and export functionality (see load data command). In addition to the typical selects, updates, and delete statements these are the only other commands that I regularly use when using MySQL.


Leave a Reply