Wednesday, December 15, 2010

How to Create a MySQL Database in Linux

A few weeks ago I blogged about how to configure a Ruby on Rails project to use MySQL as the database engine. One item I left out was how to set up the MySQL database. If you are following a Ruby on Rails tutorial that uses SQLite as the default, but are actually using MySQL, you may run into a problem when you try rake db:migrate. The database won't be found simply because it doesn't exist.

Assuming you already have MySQL installed (including libmysqlclient-dev), type:

mysql -u root -p

You will be prompted to provide the password you created when you installed MySQL. If you did not define a password, simply hit enter.

If all went well, you should now be at a mysql command prompt. Type in the following:

create database your_app_name_here;

Obviously, provide your own name for the database. Don't leave out the ';' as this is essential to MySQL accepting the command entered.

Finally, exit out of the mysql prompt with quit; and then run rake db:migrate within your Rails project folder. All will be well.

You should learn more about MySQL if you are going to use it. Click here for a tutorial.

0 comments:

Post a Comment