Saturday, April 10, 2010

Installing MySQL and ruby bindings

Installing MySQL and ruby bindings

Previous: Installing basic ruby support

MySQL Server


In Terminal, install MySQL Server with apt:

sudo apt-get install mysql-server

During installation, you will be prompted to enter a password for the root mysql user. While it's possible to run mysql with no root password, it's generally considered a good practice to use a password.

The installation will automatically start the server. To verify the installation was successful, check to see if the server is running:

ps ax | grep mysql

You can also check for the existence of this file, which exists when the server is running:

/var/run/mysqld/mysqld.pid

The commands to stop and start MySQL Server are

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

If you want to stop the server while continuing to install software, you can do so.

MySQL command-line client


I wanted to configure MySQL to put database data somewhere under my /home directory because it's in a large partition and so that it will be easy to backup and restore my data. To do this, I created the data directory and set permissions so mysql could use it:

cd
mkdir -p .mysql/data
chown mysql .mysql .mysql/data

Now stop the mysql server.

Edit the file /etc/mysql/my.cnf. Look for the section labeled [mysqld] and change (or add) the datadir specification:

datadir=/home/you/.mysql/data

After making those changes, start the server.

To see if the configuration changes worked, start a command-line client

mysql -u root -p

If it starts normally, then the server is running and the localhost connection is working. To ensure mysql is using the datadir you specified, create a test database:

create database test1;

Exit the command-line client by typing "quit". Change to the directory you specified as datadir. If you don't have permission to cd to the directory, use sudo to add read and execute privileges on it. (You need execute privileges to cd to a directory.)

MySQL GUI client


From the main menu bar, choose Applications > Add/Remove....

1. If prompted to update the list of available packages, do so.

2. Under Show, choose All available applications.

3. A few applications may be pre-selected for you. Browse the list and see if you really want any of these. De-select the checkboxes for the ones you don't want. In some cases, the system will warn you that other packages depend on the one you're trying to de-select. In that case, you will need to install it.

4. Select "MySQL Administrator" for a GUI client and "MySQL Query Browser" for a GUI tool to run queries. (If you type "my" in the Search: field, the list will jump right to these entries.)

5. Choose Apply Changes to proceed with the installation. If any of the applications requires administrator rights to install, the system will prompt for your administrator password. This is normal and not an exploit.

After the installer finishes, the two applications will appear under Applications > Programming from the main menu bar.

To ensure MySQL Administrator was installed correctly, with the MySQL server running, go to Applications > Programming and select MySQL Administrator from the menu. The program should open a window containing a form where you can enter connection information. Enter "localhost" for host, "root" for user, and the password you defined earlier for password. If you didn't define a password earlier, then leave the password field empty. Choose Connect.

Check the installation of MySQL Query Browser in the same way.

Install Ruby bindings for MySQL



Open a Terminal window and enter the following commands:

cd ~
sudo apt-get install libmysql-ruby libmysqlclient-dev

The package libmysqlclient-dev is a virtual package. When you run the command above, you will see an error message that shows the name of the real package. Substitute it in the command line and run it again. When I ran it, it showed libmysqlclient15-dev, so I ran the command this way:

sudo apt-get install libmysql-ruby libmysqlclient15-dev

Run this command to build it:

sudo gem install mysql

Expect a lot of error messages for missing definitions in ri and rdoc. As long as the gem and native extensions build okay, you're good to go.

Next: Installing Rails

No comments:

Post a Comment