Software > Mac OS X Packages > MySQL

MySQL Database Server

This page in French | This page in Chinese

Introduction

The MySQL database server is very popular for building web applications, it is often used in combination with the PHP language.

Since version 4.0.11, I am no longer building (from source code) and hosting the MySQL binary packages because the people at MySQL started to provide very nice official binary packages. I am however still providing and updating this set of installation instructions.

Installation Instructions

The first step is to download the software from the mysql.com site. First go to the downloads page at http://dev.mysql.com/downloads/mysql/4.1.html. Download the Standard installer package in the Mac OS X downloads section.

Installation Procedure

NOTE: You must have administrator rights to perform this installation.

Do this to install for the first time (see below for update instructions):

Mac OS version 10.2 and higher

  1. Download the package mentioned above to your desktop. Unpack it and then double-click on the .pkg file to install it.
  2. Open a terminal window and type in the following commands (without the double quotes):
  3. type cd /usr/local/mysql
  4. type sudo chown -R mysql data/, enter your Mac OS X account password when asked for it.
  5. To start the server, issue sudo echo first, then type sudo ./bin/mysqld_safe &
  6. Use it with /usr/local/mysql/bin/mysql test
If you do not want to have to type /usr/local/mysql/bin in front of every single mysql-related command, then you have to add the /usr/local/mysql/bin directory to your PATH environment variable in your shell's login script.

For the tcsh shell, which was the default up to Mac OS X 10.2 , you can do this by running this command once:
echo 'setenv PATH /usr/local/mysql/bin:$PATH' >> ~/.tcshrc

For the bash shell, which is the default for new user accounts created under Mac OS X 10.3, the command is:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

Then you have to close and re-open the terminal window.

After performing the above steps, read the section about User Account Management in the manual carefully, it explains how to set up permissions etc.

Important: You should at least run this command in order to secure the open master account in the default installation:

/usr/local/mysql/bin/mysqladmin -u root password new_password_here

In recent distributions of MySQL, you can also run the script mysql_secure_installation instead of just changing the root password. That script allows you to change the root password, delete the test database, remove the anonymous user, remove remote access (allowing access from the local machine only) and reset the privileges table.

Database Re-Initialization

Sometimes the scripts in the installer package do not work correctly, preventing the startup of the database server. Sometimes you need to reinitialize for other reasons, when the database is too screwed up. So if you have problems and you want a fresh start, perform these steps manually and then try again to start the server:

  1. sudo find /usr/local/mysql/data -type f -exec rm {} ';'
  2. sudo hostname 127.0.0.1
  3. cd /usr/local/mysql
  4. sudo ./scripts/mysql_install_db
  5. sudo chown -R mysql data/

Note that you will loose all data stored in the database this way.

Update Instructions

If you previously installed an older version of this package, here is what you have to do to update to the most recent version:

  1. Type this into a terminal window to save the old data:
    cd /usr/local/mysql; sudo tar -cvf /tmp/mysql-data.tar data
  2. Download and unpack the new version of the package
  3. Install it by double-clicking on the package icon and going through the installer screens
  4. Type these two commands into a terminal window to restore the old data:
    cd /usr/local/mysql; sudo tar -xf /tmp/mysql-data.tar
    sudo chown -R mysql /usr/local/mysql/data/*
  5. Reboot the machine
  6. Unless you have the StartupItem installed, start the DB server again:
  7. type cd /usr/local/mysql
  8. type sudo echo first, then type sudo ./bin/mysqld_safe &

All your data and settings will be preserved, unless this is a major version update, in which case the table format might have changed (doesn't happen often). In these cases, you have to dump and re-import the data, and you must not do the two lines with the tar command above.

Please note, that after upgrading from MySQL 3.23 to MySQL 4.0 it is recommended to convert the MySQL privilege tables using the mysql_fix_privilege_tables script, since some new security privileges have been added.

Please see http://www.mysql.com/doc/en/Upgrading-from-3.23.html for more information on how to upgrade from MySQL 3.23.

Examples

FAQ

This section list a few frequently asked questions and their answers.

I have permission problems while connecting to the database server
I have trouble, the database is screwed up and nothing works, so I want to reset everything and start again.

Check out the Database Re-Initialization section above.

Why do I get the message
Sorry, the host 'your_hostname_here' could not be looked up.
Please configure the 'hostname' command to return a correct hostname.

There is a problem with the DNS configuration for the IP address you're using. Often, the forward and reverse DNS entries for it do not match. This is usually a problem your network administrator or ISP has to fix.

Someone sent me this useful workaround: just type sudo hostname 127.0.0.1, then issue the command again.

Why do I get the message
ERROR 1148: The used command is not allowed with this MySQL version
when I try to use LOAD DATA LOCAL INFILE?

Please read this

Why do I get messages like
undefined reference to _BC expected to be defined in /usr/lib/libSystem.B.dylib
when I try to use mysql?

You installed the wrong MySQL package (the one I made for Mac OS X 10.1) on a machine running Mac OS X 10.2 (or you never updated MySQL after updating to Mac OS X 10.2).

Why do I get the message
ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
when I try to connect to the DB using the mysql command line client?

Most likely you didn't start up the DB server. Try this:
cd /usr/local/mysql;
sudo echo
sudo ./bin/mysqld_safe &
Then try to connect again.

Why do I get the message mysqld ended when I try to start up the DB server with the safe_mysqld command?

Look at the end of the .err file(s) in your mysql data directory.
Whenever you see mysqld ended, these .err files will tell you the exact reason why the server refuses to start up.

How can I remove this package if I need to for some reason?

You can use the script on the cleanup instructions page.

How can I use the InnoDB table type to get transactions, row-level locking etc. ?

Look at my InnoDB page.

Additional Information

Build Instructions

Here are the general steps needed to create the package from source.

6. January 2007