Search the MySQL manual:

2.1.3 Installing MySQL on Mac OS X

Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.2 (``Jaguar'') using a Mac OS X PKG binary package instead of the binary tarball distribution. Please note that older versions of Mac OS X (for example, 10.1.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.

NOTE: 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 actually install the MySQL PKG, double click on the package icon. This launches the Mac OS Package Installer, which will guide you through the installation of MySQL.

The Mac OS X PKG of MySQL will install itself into `/usr/local/mysql-<version>' and will also install a symbolic link `/usr/local/mysql', pointing to the new location. If a directory named `/usr/local/mysql' already exists, it will be renamed to `/usr/local/mysql.bak' first. Additionally, it will install the grant tables in the mysql database by executing mysql_install_db after the installation.

The installation layout is similar to the one of the 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.2.7 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, you already have a version of MySQL installed:

This manual section covers the installation of the official MySQL Mac OS X PKG only. Make sure to read Apple's help about installing MySQL (Run the ``Help View'' application, select ``Mac OS X Server'' help, and do a search for ``MySQL'' and read the item entitled ``Installing MySQL'').

Especially note that the pre-installed version of MySQL on Mac OS X Server starts the MySQL user with the command safe_mysqld instead of mysqld_safe.

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 version 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 using the mysql_fix_privilege_tables script, since some new security privileges have been added. See section 2.5.2 Upgrading From Version 3.23 to 4.0.

After the installation, you can start up MySQL by running the following commands in a terminal window. Please note that you need to have administrator privileges to perform this task.

shell> cd /usr/local/mysql
shell> sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
shell> bg
(Press Control-D to exit the shell)

You should now be able to connect to the MySQL server, for example, by running `/usr/local/mysql/bin/mysql'.

If you installed MySQL for the first time, please remember to set a password for the MySQL root user!

This is done with the following two commands:

/usr/local/mysql/bin/mysqladmin -u root password <password>
/usr/local/mysql/bin/mysqladmin -u root -h `hostname` password <password>

You might want to also add aliases to your shell's resource file to access mysql and mysqladmin from the command line:

alias mysql '/usr/local/mysql/bin/mysql'
alias mysqladmin '/usr/local/mysql/bin/mysqladmin'

Alternatively, you could simply add /usr/local/mysql/bin to your PATH environment variable, for example, by adding the following to `$HOME/.tcshrc':

setenv PATH ${PATH}:/usr/local/mysql/bin

To enable the automatic startup of MySQL on bootup, you can download Marc Liyanage's MySQL StartupItem from the following location:

http://www2.entropy.ch/download/mysql-startupitem.pkg.tar.gz

We plan to add a StartupItem to the official MySQL PKG in the near future.

Please 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.

After you have copied over the MySQL database files from the previous version and have successfully started the new version, 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

Posted by prc8895 on Monday May 5 2003, @1:07am[Delete] [Edit]

I also am having difficulty with MySQL on powerbook but I do have MySQL up and running following those direction. The person who posted that previous comment: I don't know if you have done this yet but I logged in as ROOT to install mysql. This is done by first activating root user and then logging out and logging back in as ROOT.

Posted by prc8895 on Monday May 5 2003, @3:27am[Delete] [Edit]

Everything is up and running. I was right that you have to be logged in as 'root' not 'ROOT' to install and run mysql. You can run it under a differnt user name but you can only run mysql and mysqladmin by the command line
sudo /usr/local/mysql/bin/mysql -p
sudo /usr/local/mysql/bin/mysqladmin -p
to run any command lines you want.

I alias them right away so I don't have to type it in all the time
alias mysql 'sudo /usr/local/mysql/bin/mysql -p'
alias mysqladmin 'sudo /usr/local/mysql/bin/mysqladmin -p'

that way I only have to type: mysqladmin status
then type in my root password to get the status report.

remember that the first time you run sudo in a terminal window you have to enter the login password for the root system user and then the password for the root mysql user. From then on all command line actions require the root mysql user password.

Posted by prc8895 on Monday May 5 2003, @4:52am[Delete] [Edit]

Hehe yet another comment on this subject. So i spent all night figuring out how to install MySQL on my PowerBook G4 with OS 10.2.5. The above steps are correct in installing the software. Here is another helpful tip though

In my comment post above I describe the aliases for a non root user. Here I'm going to show you how to setup terminal so you don't have to type those aliases into every new terminal window.

In this type this into the terminal window:
echo "source /usr/share/tcsh/examples/rc" > ~/.tcshrc
echo "source /usr/share/tcsh/examples/login" > ~/.login
echo "source /usr/share/tcsh/examples/logout" > ~/.logout

Then type:
mkdir ~/Library/init <- This might already be created
mkdir ~/Library/init/tcsh

Then type:
cd ~/Library/init/tcsh
pico aliases.mine

In the pico document enter the following text
alias mysqladmin 'sudo /usr/local/mysql/bin/mysqladmin -p<yourrootpassword>'
alias mysql 'sudo /usr/local/mysql/bin/mysql -p<yourrootpassword>'
alias mysqlstart 'echo Press CTRL+Z; echo Then type "bg" and hit enter; cd /usr/local/mysql; sudo ./bin/mysqld_safe'

Ok <yourrootpassword> = the password you setup for root access in MySQL. it is not a typeo either that it reads -p<yourrootpassword> they must be together with no spaces.

Ok so what did we just do? To tell you the truth i'm not 100% sure but what I do know is that terminal comes with some custom settings as well as the ability to allow the user to make their own settings. Those echo statements bascially turn these features on in terminal. I added the alias mysqlstart because the startup sequence for MySQL was a pain to type in every time and this does it for you as well as tell you what keys to press to properly get out of the window.

If you want more info on custom terminal settings type
pico /usr/share/tcsh/examples/readme
that file has more information also you should type
pico /usr/share/tcsh/examples/aliases
this is the new commands that come with terminal but are not avalible right away.

Posted by Scott Haneda on Tuesday May 6 2003, @11:14pm[Delete] [Edit]

I would highly recomend NOT following the steps posted by Nicky Vu, unless you really know what you are doing and why in the world you would want to hard code any password into any file and furthermore, alias it so anyone only need type mysql and gain full access. Follow the steps in the install notes, and you will be fine.

Posted by Dave Nathanson on Wednesday May 7 2003, @6:41pm[Delete] [Edit]

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!

Posted by braintrino @ ComputationalNeuralSystems.com on Thursday May 29 2003, @9:32pm[Delete] [Edit]

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.

Posted by braintrino @ ComputationalNeuralSystems.com on Wednesday May 14 2003, @8:21am[Delete] [Edit]

By the way, DO NOT EVER follow the above user prc8895's example to
echo "source /usr/share/tcsh/examples/rc" > ~/.tcshrc
echo "source /usr/share/tcsh/examples/login" > ~/.login
echo "source /usr/share/tcsh/examples/logout" > ~/.logout

These commands will wipe out all your local .tcshrc, .login and .logout settings!!! You won't be able to access anything afterwards!!

Posted by braintrino @ ComputationalNeuralSystems.com on Wednesday May 14 2003, @9:50pm[Delete] [Edit]

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.

Posted by Russell Almond on Friday May 16 2003, @12:38pm[Delete] [Edit]

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.

Posted by Jose Javier Delgado-Esteban on Friday July 11 2003, @10:58am[Delete] [Edit]

Hi there, I have been trying to set up MySQL server on my Mac running the latest version of OX. This is what I get after following the instructions on the site:


[iBook:~] root# cd /usr/local/mysql
[iBook:/usr/local/mysql] root# sudo ./bin/mysqld_safe
Starting mysqld daemon with databases from /usr/local/mysql/data
^Z
Suspended
[iBook:/usr/local/mysql] root# bg
[1] sudo ./bin/mysqld_safe &
[iBook:/usr/local/mysql] root# logout
[Process completed]


Up to here everything seems fine but then when a I try to connect to the server I get:

Last login: Wed Jul 9 21:08:44 on ttyp1
Welcome to Darwin!
[iBook:~] root# /usr/local/mysql/bin/mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
[iBook:~] root#


Could anyone help me?

Many thanks

Posted by Balinder Walia on Tuesday August 5 2003, @12:40pm[Delete] [Edit]

Try the following instead

/usr/local/mysql/bin/mysql -p

Means login and ask for password which is just created

Posted by Shannon Lenz on Friday August 8 2003, @6:47pm[Delete] [Edit]

Would someone please show the correct command lines for resetting the passwords. The information listed on the site does not seem to be Mac-centric. Kudos to braintrino, you really helped me alot with your clear concise command line info. Just got to figure out that password thingie.

Add your own comment.