MySQL on Leopard

Today I continued setting up my Mac (OS X 10.5.5) with server software. Apache is already running, as described in my previous post – next is a MySQL database.

I downloaded MySQL 5.1.30 as Mac OS X 10.5 (x86_64) package from here. Install instructions for MySQL under OS X are available on the MySQL webpage (see here), however, everything is pretty straightforward:

  1. I opened the downloaded disk image, double clicked the install package (mysql-5.1.30-osx10.5-x86_64.pkg), and ran through the installation process (can’t be easier).
  2. Next I installed the MySQL startup item (MySQLStartupItem.pkg). Again, simply click through the install process, nothing special to do.
  3. Then I opened a terminal and used the startup item to start the database with MySQLCOM start:
    mbp:~ gerhard$ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
    Starting MySQL database server
  4. At this point, MySQL was already up and running, great. It runs with a user named “_mysql”, that’s ok, too. Next I extended my PATH environment variable, so that I can use MySQL programs from the command line.In my case (bash shell), I added PATH=$PATH:/usr/local/mysql/bin to my .profile file in my user’s home directory. /usr/local/mysql is where the installer installed MySQL.
  5. The last thing to do, is post installation setup and testing (full instructions can be found on the MySQL webpage). The following steps show all I had to do.
  6. Grant tables have already been set up during the install process, because I used the install package of MySQL.
  7. On the terminal, mysqladmin version and mysqladmin variables can be used to see information about the database. If the database is not running, these programs will show error messages.
  8. Now it’s necessary to connect to the database, remove the anonymous user (as I don’t need it…), and assign a password to the DB root user (after installation there is no password!). In this example, I set the password to “pass”. A password must be assigned for all hosts the user can connect from. Use the query select host, user from mysql.user; to find out which hosts these are (for user root) – in this example I set passwords for root@localhost and [email protected].
    mbp:~ gerhard$ mysql -u root
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.1.30 MySQL Community Server (GPL)

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

    mysql> drop user '';
    Query OK, 0 rows affected (0.00 sec)

    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pass');
    Query OK, 0 rows affected (0.00 sec)

    mysql> SET PASSWORD FOR 'root'@'' = PASSWORD('pass');
    Query OK, 0 rows affected (0.00 sec)

  9. To make starting and stopping more comfortable, I added two aliases to my .profile file:
    alias startmysql='sudo /Library/StartupItems/MySQLCOM/MySQLCOM start'
    alias stopmysql='sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop'

    This way, I can open a terminal and just type startmysql and stopmysql to start and stop MySQL.

That’s it – MySQL is installed and ready to be worked with.

Edit: Later I found out that there was even a preference pane item in the MySQL dmg file. Simply open MySQL.prefPane to install it. This will add a MySQL pane to your System Preferences application. Within this pane you can easily start up and shut down your MySQL installation and you can define if you want MySQL to automatically start when your system boots.

Comments are closed.