Jul 12

Setup MySQL database for Rails

wzuup mysql

Login to the MySQL instance.

$ sudo mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 174
Server version: 5.0.32-Debian_7etch5-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


Create the database for the rails app.

mysql> CREATE DATABASE IF NOT EXISTS wzuup_production;

Create a user and give him a password.

mysql> GRANT ALL PRIVILEGES ON wzuup_production.*
    -> TO "wzuup_username"@"localhost" 
    -> IDENTIFIED BY "wzuup_password";

Type quit or press CTRL+D to quit MySQL.

mysql> quit

Change the RAILS_PROJECT/config/attachment:database.yml to have the same user and password as in the SQL statement above.

  adapter: mysql
  encoding: utf8
  database: wzuup_production
  username: wzuup_username
  password: wzuup_password
  socket: /var/run/mysqld/mysqld.sock

Create the schema in the created database using the migrations.

Important: Set the environment to production!

$ rake RAILS_ENV=production db:migrate
✱ ✱ ✱