Changes to UsingMySQLAsDataBackend
You are here: Home > Using MySQL as Data Backend

Using MySQL as Data Backend

Before starting, make sure that the MySQL database server is correctly installed and running. The process described here was tested for version 4.1, but is likely to work on other versions too.

TCP Connection

Motiro tries to connect to the MySQL server using a TCP socket. You will need to make sure the server is up and listening for connections on port 3306 (MySQL default port). If you're not sure, try issuing the command

% telnet localhost 3306

The output should look something like

7
<code> 4.1.18-nt</code>
<code>       xH?@cU]S,�!?h3d{bUf~jv5A</code>

You may need to set up your MySQL server to accept TCP connections, if you are sure the server is running and it doesn't respond to the above command. You may also set up your MySQL server to answer only to connections originated from the localhost, if you feel opening the port is a security issue. For more information, please see the MySQL user guide.

Database creation

Motiro uses the empty-passworded username 'motiro' to authenticate to the MySQL server. It may need to access three differente databases, depending on the execution context. The database names are

You will need to make sure those databases are present and fully-acessible to the user motiro. The following script will do the trick. It is a command-line script using the mysql client, but you may use any tool you'd prefer (maybe a GUI or web-based one). Just make sure to create the databases with the exact names and to grant all privileges to the motiro user in them.

To use the mysql client just fire it as the root user and say (lines starting with '%' are commands to my shell and with 'mysql>' are to the MySQL database, others are the system responses to them):

% mysql -u root -p
Enter password: ***********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13 to server version: 4.1.18-nt

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

mysql> create database motiro_development;
Query OK, 1 row affected (0.00 sec)

mysql> create database motiro_test;
Query OK, 1 row affected (0.00 sec)

mysql> create database motiro_production;
Query OK, 1 row affected (0.02 sec)

mysql> grant all on motiro_development.* to motiro;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on motiro_test.* to motiro;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on motiro_production.* to motiro;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Point to MySQL

The file config/database.yml is the one that points to the database backend that Motiro should user. The default setup right now is to use SQLite 3. In order to use you newly-created MySQL databases, change the file contents for what you see below.

  development:
    adapter: mysql
    database: motiro_development
    host: 127.0.0.1
    port: 3306
    username: motiro
    password:
  test:
    adapter: mysql
    database: motiro_test
    host: 127.0.0.1
    port: 3306
    username: motiro
    password:
  production:
    adapter: mysql
    database: motiro_production
    host: 127.0.0.1
    port: 3306
    username: motiro
    password:

Preparing the schema

Last step for setting your databases is setting up their schemas correctly. Fortunately, Motiro comes prepackaged with migration scripts for this purpose. You will need to ask rake to run them.

% rake migrate

This last step is exactly the same thing that should be done for the default set up. From now on you can refer to the main instructions.

Last update by thiagoarrais at Wed, 27 Aug 2008 12:18:48 -0500

Edit (requires authentication) | View raw text | Page history (5 revisions)