The world's most popular open source database
Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.3.x (“Panther”) or newer using a Mac OS X binary package in PKG format instead of the binary tarball distribution. Please note that older versions of Mac OS X (for example, 10.1.x or 10.2.x) are not supported by this package.
The package is located inside a disk image
(.dmg) file that you first need to mount by
double-clicking its icon in the Finder. It should then mount the
image and display its contents.
To obtain MySQL, see Section 2.1.3, “How to Get MySQL”.
Before proceeding with the installation, be sure to shut down all running MySQL server instances by either using the MySQL Manager Application (on Mac OS X Server) or via mysqladmin shutdown on the command line.
To install the MySQL PKG file, double-click on the package icon. This launches the Mac OS X Package Installer, which guides you through the installation of MySQL.
Due to a bug in the Mac OS X package installer, you may see this error message in the destination disk selection dialog:
You cannot install this software on this disk. (null)
If this error occurs, simply click the Go Back button once to return to the previous screen. Then click Continue to advance to the destination disk selection again, and you should be able to choose the destination disk correctly. We have reported this bug to Apple and it is investigating this problem.
The Mac OS X PKG of MySQL installs itself into
/usr/local/mysql-
and also installs a symbolic link,
VERSION/usr/local/mysql, that points to the new
location. If a directory named
/usr/local/mysql exists, it is renamed to
/usr/local/mysql.bak first. In addition, the
installer creates the grant tables in the mysql
database by executing mysql_install_db.
The installation layout is similar to that of a
tar file binary distribution; all MySQL
binaries are located in the directory
/usr/local/mysql/bin. The MySQL socket file
is created as /tmp/mysql.sock by default. See
Section 2.1.5, “Installation Layouts”.
MySQL installation requires a Mac OS X user account named
mysql. A user account with this name should
exist by default on Mac OS X 10.2 and up.
If you are running Mac OS X Server, a version of MySQL should already be installed. The following table shows the versions of MySQL that ship with Mac OS X Server versions.
| Mac OS X Server Version | MySQL Version |
| 10.2-10.2.2 | 3.23.51 |
| 10.2.3-10.2.6 | 3.23.53 |
| 10.3 | 4.0.14 |
| 10.3.2 | 4.0.16 |
| 10.4.0 | 4.1.10a |
This manual section covers the installation of the official MySQL Mac OS X PKG only. Make sure to read Apple's help information about installing MySQL: Run the Help View application, select Mac OS X Server help, search for “MySQL”, and read the item entitled “Installing MySQL”.
For preinstalled versions of MySQL on Mac OS X Server, note especially that you should start mysqld with safe_mysqld instead of mysqld_safe if MySQL is older than version 4.0.
If you previously used Marc Liyanage's MySQL packages for Mac OS X from http://www.entropy.ch, you can simply follow the update instructions for packages using the binary installation layout as given on his pages.
If you are upgrading from Marc's 3.23.x versions or from the Mac OS X Server version of MySQL to the official MySQL PKG, you also need to convert the existing MySQL privilege tables to the current format, because some new security privileges have been added. See Section 4.4.5, “mysql_fix_privilege_tables — Upgrade MySQL System Tables”.
If you want MySQL to start automatically during system startup, you also need to install the MySQL Startup Item. Starting with MySQL 4.0.15, it is part of the Mac OS X installation disk images as a separate installation package. Simply double-click the MySQLStartupItem.pkg icon and follow the instructions to install it. The Startup Item need be installed only once. There is no need to install it each time you upgrade the MySQL package later.
The Startup Item for MySQL is installed into
/Library/StartupItems/MySQLCOM. (Before MySQL
4.1.2, the location was
/Library/StartupItems/MySQL, but that
collided with the MySQL Startup Item installed by Mac OS X
Server.) Startup Item installation adds a variable
MYSQLCOM=-YES- to the system configuration file
/etc/hostconfig. If you want to disable the
automatic startup of MySQL, simply change this variable to
MYSQLCOM=-NO-.
On Mac OS X Server, the default MySQL installation uses the
variable MYSQL in the
/etc/hostconfig file. The MySQL Startup Item
installer disables this variable by setting it to
MYSQL=-NO-. This avoids boot time conflicts
with the MYSQLCOM variable used by the MySQL
Startup Item. However, it does not shut down a running MySQL
server. You should do that yourself.
After the installation, you can start up MySQL by running the following commands in a terminal window. You must have administrator privileges to perform this task.
If you have installed the Startup Item, use this command:
shell>sudo /Library/StartupItems/MySQLCOM/MySQLCOM start(Enter your password, if necessary)(Press Control-D or enter "exit" to exit the shell)
For versions of MySQL older than 4.1.3, substitute
/Library/StartupItems/MySQLCOM/MySQLCOM with
/Library/StartupItems/MySQL/MySQL above.
If you do not use the Startup Item, enter the following command sequence:
shell>cd /usr/local/mysqlshell>sudo ./bin/mysqld_safe(Enter your password, if necessary)(Press Control-Z)shell>bg(Press Control-D or enter "exit" to exit the shell)
You should be able to connect to the MySQL server, for example, by
running /usr/local/mysql/bin/mysql.
The accounts that are listed in the MySQL grant tables initially have no passwords. After starting the server, you should set up passwords for them using the instructions in Section 2.10, “Post-Installation Setup and Testing”.
You might want to add aliases to your shell's resource file to make it easier to access commonly used programs such as mysql and mysqladmin from the command line. The syntax for bash is:
alias mysql=/usr/local/mysql/bin/mysql alias mysqladmin=/usr/local/mysql/bin/mysqladmin
For tcsh, use:
alias mysql /usr/local/mysql/bin/mysql alias mysqladmin /usr/local/mysql/bin/mysqladmin
Even better, add /usr/local/mysql/bin to your
PATH environment variable. You can do this by
modifying the appropriate startup file for your shell. For more
information, see Section 4.2.1, “Invoking MySQL Programs”.
If you are upgrading an existing installation, note that installing a new MySQL PKG does not remove the directory of an older installation. Unfortunately, the Mac OS X Installer does not yet offer the functionality required to properly upgrade previously installed packages.
To use your existing databases with the new installation, you will
need to copy the contents of the old data directory to the new
data directory. Make sure that neither the old server nor the new
one is running when you do this. After you have copied over the
MySQL database files from the previous installation and have
successfully started the new server, you should consider removing
the old installation files to save disk space. Additionally, you
should also remove older versions of the Package Receipt
directories located in
/Library/Receipts/mysql-.
VERSION.pkg


User Comments
If you're as new as I am to Unix, you'll need to know that if the commands don't work for you, and you've already CD-ed into the correct directory, try prepending a ./ to the beginning of the command.
If the current working directory (spelled .) is not in your path (which is the proper thing), then type the command as:
./mysqladmin
meaning "look for the mysqladmin file in this directory and execute it."
The alternate method is to type the full path to the command as:
/usr/local/mysql/bin/mysqladmin
Hope this helps somebody. It sure helped me!
Ok, for those of you who get this message "mysqld ended" after installation, such as:
shell> cd /usr/local/mysql
shell> sudo ./bin/mysqld_safe
Password:
Starting mysqld daemon with databases from /usr/local/mysql/data
030507 11:51:57 mysqld ended
Here's the scope to fix it:
You probably have a previously installed mySQL, and the package upgraded it (preserving the old settings) instead of doing a clean install.
You have to delete the /Library/Receipts/mysql-<version>.pkg to trick the installer to do a clean installation rather than an upgrade.
Log in as root. You have to enable root user for MacOSX. To do so, launch NetInfo Manager (living under Applications>Utilities). Pull down Security>Authenticate and then Security>Enable Root User.
shell> cd /Library/Receipts
find the mysql-<version>.pkg file and delete it.
shell> rmdir mysql-standard-4.0.12.pkg
Log out as yourself, and log in as root.
Reinstall from the mysql-standard-4.0.12.pkg
This time when you install from the package, the last button in the installation process will say "Install" instead of "Upgrade".
Finish the installation, and follow the instruction from the web:
http://www.mysql.com/doc/en/Mac_OS_X_installation.html
Ignore the instructions that come with the ReadMe.txt file!
That is:
shell> cd /usr/local/mysql
shell> sudo ./bin/mysqld_safe
Password: myrootpassword
ctrl-z
bg
To make life easier, alias the mysql and mysqladmin commands first:
shell> alias mysql '/usr/local/mysql/bin/mysql'
shell> alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
Then set mySQL passwords:
shell> mysqladmin -u root password mysqlpassword
shell> mysqladmin -u root -h localhost password mysqlpassword
where "mysqlpassword" is your password for accessing mySQL.
If you need to access it via the local web, turn on Personal Web Sharing (lives in Sharing under System Preferences). You will find the URL for your localhost listed in the Web Sharing window. Better yet, use the generic URL:
http://localhost/~mymacusername/
or
http://rendezvous-name.local/~mymacusername/
where the actual "rendezvous-name.local" is listed in the Sharing under System Preferences.
It points to the folder inside /User/mymacusername/Sites
Go back to NetInfo Manager, and Disable Root User! Leaving Root User enabled is a security risk for your computer.
After you have setup mySQL, there is an excellent web-based tool to admin mySQL called phpMyAdmin. It saves you tons of typing or getting lost. It makes managing mySQL a breeze.
http://www.phpmyadmin.net/
It is a php tool, and php is already installed in MacOSX so everything is ready to go, and you don't need to do anything except installing phpMyAdmin.
I have another solution for the 'Database ended' problem on installation which does not require activating the root user account.
After a clean install of MySQL from the pkg, I got the following error:
% sudo ./bin/mysqld_safe
Password:
Starting mysqld daemon with databases from /usr/local/mysql/data
030516 15:07:57 mysqld ended
Checking the log files, I found that there were incorrect permissions on some of the files. The following steps (from the INSTALL_BINARY readme) fixed the problem:
% cd /usr/local/mysql
% sudo chown -R mysql data
% sudo chgrp -R mysql .
Permission were now correct and mysqld_safe ran as expected.
"MySQL Startup Item" would not install and gave no reason for the failure. Since I have only recently installed 10.2.8, the directory /Library/StartupItems/ did not exist. As soon as I created the directory manually the problem was solved.
JD
When setting the root pasword for mysql
for the mysqladmin -u root password <password>
there is a -p missing for the password.
as a result this throws up the error
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user: 'root'@'localhost' (Using password: NO)'
It is my belief that as of Panther, the default shell went to bash. As such, the method for altering the user's path is now:
echo 'export PATH=/Library/MySQL/bin:$PATH' >> ~/.bash_profile
I should be last one to be offering 'nix code but I will say that the tcsh code for altering the Path wasn't working in Panther.
The default shell changed from tcsh to bash in Panther, but only for users created under Panther.
In response to one post earlier that involved activating the root user: You never have to activate the root user. Activating the root user enables anyone (who knows the root password) to log in to the GUI as root, which could be a very big breach of security. Instead, use the sudo (meaning "super user do...") command. So instead of:
shell>chown ...
do
shell>sudo chown ...
This will prompt for a password; enter any current user's password who is an administrator of the computer, and that one command will execute as root.
Restart MySQL using Mac OSX (usefull on update)
sudo ./bin/mysqladmin shutdown
Redemarrer MySQL sous OSX
If you use the option to set the variable in the hostconfig file
MYSQLCOM=-NO-
to not start the MySQL server on startup (with the StartupItem installed, of course)
you can't use
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
but must use
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
at least on my System (Mac OS 10.3.6, mySQL 4.1.7)
I have the same problem...MACOSX server 10.3.6 ..latest release of phpmyadmin...
I made the mistake of adding a root@localhost password to phpmyadmin and now I get the socket error...additionally...mySQLManager won't launch anymore either...I'm posting all over the place...hopefully I'll have a suggestion for someone soon..
With all the instructions above, I can successfully installed MySQL on my Mac OS X server.
Now, I am looking for a good and easy-to-use GUI. Searching through google, I found a great GUI which is called Navicat. http://www.navicat.com
After I read a review by O'Relly, http://www.onlamp.com/pub/a/onlamp/2004/12/22/navicat.html , I realized it is the GUI that I am looking for.
Previous messages suggest activating the root user.
You can get a root shell by typing
sudo -s
followed by the password
from then on you are in a root shell, and can enter commands just as if you had logged in to an activated root login.
do a ctrl-d or type exit to return to your normal userid.
MB
If you're trying to use MySQL with phpMyAdmin, you've set up the phpMyAdmin's config.inc.php, and you're getting an error saying "Client does not support authentication protocol requested by server; consider upgrading MySQL client", you need to set the password on the mysql command line using the OLD_PASSWORD('password') routine.
For example:
tcsh: mysql
mysql> SET PASSWORD FOR root@localhost = OLD_PASSWORD('mypassword');
If you're trying to use MySQL with phpMyAdmin, you've set up the phpMyAdmin's config.inc.php, and you're getting an error saying "Client does not support authentication protocol requested by server; consider upgrading MySQL client", you need to set the password on the mysql command line using the OLD_PASSWORD('password') routine.
For example:
tcsh: mysql
mysql> SET PASSWORD FOR root@localhost = OLD_PASSWORD('mypassword');
Always using an installation that is nearer to some kind of default setting, I used :
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
and it worked.
Using the echo trick has the side-effect of letting your .profile intact. If you mess with .profile, you won't be able to do anything with your shell. You will have to revert to another shell (setting the Terminal's Preferences accordingly, e.g. /bin/csh) and then erase your .profile.
To discover this bit of knowledge took me about two hours this morning.
Hope this is correct and helpful,
Benoit St-Pierre
For MacOS X 10.3 and up...
Setting the environment path was a little difficult for me being a newbie in MacOS UNIX...but I found a little tidbit through various research.
The problem arose when trying to use client tools for MySQL 5.0 and realizing the older 4.0 tools were loading when opening a terminal window or any SSH shell.
To set the environment for all users to include the CURRENT (not preloaded) version of mySQL, edit the /etc/profile file PATH variable. Just add the /usr/local/mysql/bin directory and save (NOTE: You will need to login as SU)
*Attention Dreamweaver Users*
When attempting to connect to a database in Dreamweaver you will get an error message like:
"Connection failed reason unknown" or
"Could not connect to '/var/mysql/mysql.sock'"
This is because, as listed above:
"The MySQL socket file is created as /tmp/mysql.sock by default."
To fix this you will need to create a new folder on your desktop named "mysql" (minus quotes). Then open a terminal.
Change directory to "var" by typing "cd /var". Once in that directory type:
"sudo mv /Users/<your user name here>/Desktop/mysql/ mysql"
You will be prompted for your password. After entering your password you will see the folder dissappear from your desktop. If you type "ls" at the prompt it should now be listed in the "var" directory. Since copying of sockets is not allowed the mysql.sock file located in the "tmp" directory will have to be moved.
So change your directory to "/var/mysql" which you just created. Then at the prompt type:
"sudo mv /tmp/mysql.sock mysql.sock"
This should move "mysql.sock" to "/var/mysql" and you can once again check by typing "ls".
Now, when you go back to Dreamweaver and hit that select button to find your database, it should pop right up!
Just don't forget to tell your other MySQL helper apps like MySQL Administrator where the new socket is.
This is only a temporary fix and will have to be done again if the server is stopped.
I hope this is useful info. BTW the version of Dreamweaver this tip is intended for is MX. I have no idea if this is a problem for newer versions.
Lee Woodrough
The installation of MySQL 5.0.22 on Mac OS X 10.4.6 using the MySQL supplied .pkg files works perfectly with no additional modifications required. MySQL, StartupItems, and the Preferences Panel installed without a problem. The easiest way to administer the MySQL server once it is installed is to also download the MySQL Administrator tool from MySQL. The Administrator tool also installs easily without any problems and allows you to delete the Anonymous account, Test DB and set all of the MySQL configuration settings without having to resort to using the command line to setup the server. Thank you MySQL for such great software.
I'm a little new to working with MySQL on our new Xserve G5. I was expecting a horrible time installing this, tons of files that would need to be compiled and installed in Terminal. I'm not bad in Terminal, but what a waste of time when it could be so much easier. Anyways, I just wanted to leave this review saying that this was EXTREMELY EASY to install, and it works GREAT! Thanks MySQL for all the time you spent on making a wonderful easy installer application, and GREAT documentation as well!
Thanks,
Paul
For those of you running on Mac OS 10.3 (Panther) like myself, this tip may save you a few hours...
I installed the MySQL 5 package from this website, and when I first tried to connect to the database using php4 (the preinstalled version that comes with MacOSx) I got an "or die" error that looked something like this -->
Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client
Solution:
save yourself some trouble and just read this...
http://dev.mysql.com/doc/refman/5.0/en/old-client.html
This is just a quick and dirty fix. A better solution would be to upgrade php to version 5, but to do so you would also have to update apache as well. If your lazy like me this will do just fine.
After the installation of MySQL 5.0 using the packages on Mac OS X Server 10.4.8 (Tiger) I had problems logging into MySQL:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (13)
The deamon was up and running (find out with % top -l 1 | grep mysql). When I was root, I could log in with no problem. To fix this, I added the execution permission for anyone to /var/mysql/ with the following command:
% sudo chmod o+x /var/mysql
Had the same problem.
Definitely first go to the Library/Reciepts (not user account, on Macintosh HD's Library)
delete the reciepts that contain the name mysql.
With those there, the installer thinks it should do an upgrade.
now run the installer.
Whoa, same error, right?
well, install the startup item as well, now the install the preference pane.
For some reason, MySQL fails to mention this at all in their documentation.
To install the preference pane, just double click it.
Ok, should be installed and available under System Preferences.
click on it.
click on Start MySQL Server
the first time you do it you'll be asked for your password, twice actually!
Unfortunately, they've failed to make a prompt that tells you why or what for.
I can only assume it is to allow some sudo shell commands...
come on MySQL AB, clearly OS X is a big user group now, support it better.
Lots of Rails developers are using OS X, if nobody else.
You want to sell books and test certifications right? Here's a user group used to paying money for things!
Don't leave it all up to the good will of Marc Liyanage
It can be much simpler.
sudo cp /etc/php.ini.default /etc/php.ini
sudo chmod 777 /etc/php.ini
Open the file with a nice Editor, like PathFinder or BBEdit.
Find the line for the mysql.default.host
; Default socket name for local MySQL connects. If
empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /tmp/mysql.sock
and enter: /tmp/mysql.sock
You will then have:
; Default socket name for local MySQL connects. If
empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /tmp/mysql.sock
save it, go back to terminal and enter:
sudo chmod 644 /etc/php.ini
You then can restart Apache and SQL, or do a normal restart. It should work afterwards.
Once I had a problem, that the mysql.socket was not copied into the /tmp folder, but it just happened once and was fixed with a new install.
PHP in Leopard (OS X 10.5) looks for the socket at /var/mysql/mysql.sock
The MySQL 5.0.45 installer by makes a socket at /tmp/mysql.sock
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock
Then my old PHP code works with MySQL.
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock
Are those last two lines necessary?
From what I've read, the permissions on a symbolic link are determined by the permissions on the target of the symbolic link.
Add your own comment.