Note: before proceeding, make sure the root, or super, user account is enabled.
Note: The dollar sign character ($) included in the following command line examples is used to indicate The Terminal’s prompt. It should not be typed in any of the directions listed below.
- Visit the Download MySQL Community Server section of the Oracle web site and download mysql-5.6.15-osx10.7-x86_64.dmg, which is the 64-bit version of MySQL 5.6.x for Mac OS X 10.7 or higher, or download the file directly from mysql-5.6.15-osx10.7-x86_64.dmg.
- You don’t need to open an account at Oracle to download MySQL. Click “No thanks, just start my download” to continue.
- Double-click the mysql-5.6.13-osx10.7-x86_64.dmg disk image file.
- Choose mysql-5.6.13-osx10.7-x86_64.pkg and use your mouse’s secondary click option (right-click for righties; left-click for lefties) and choose the first option from the menu: “Open.” (The MySQL.prefPane and MySQLStartupItem.pkg files won’t be used in this tutorial, but, feel free to install them if you want a GUI for starting and stopping MySQL.)
- Launch The Terminal.
- Start MySQL. You’ll need your root password for this step.
$ sudo /usr/local/mysql/bin/mysqld_safe
- Your Terminal’s prompt should be hanging.
- Open another Terminal window: command + N
- Make sure you’re home.
$ cd
- Set the root password, replacing YOUR_PASSWORD with your own password.
$ sudo /usr/local/mysql/bin/mysqladmin -u root password 'YOUR_PASSWORD'
- Your password is now sitting in a plain text file called .bash_history, which is in your home folder. Type the following to clear it:
$ history -c
- Verify your having cleared the file.
$ historyYou should not see your password in the output.
- Log in to MySQL as the root user.
$ /usr/local/mysql/bin/mysql -u root -p
- Enter your password. Your output should look very similar to
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.15 MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
- Exit MySQL.
mysql> exit
- Navigate to the etc folder.
$ cd /etc
- A file called php.ini.default resides in the etc folder. We’ll need to rename it to php.ini so that we can configure MySQL to work with PHP.
$ sudo cp php.ini.default php.ini
- Assume the super user, or root, identity. You’ll need your rootpassword.
$ su
- Note the permissions (likely -r--r--r--) on php.ini.
$ ls -la php.ini
- We’ll change permissions on the file temporarily so we can edit it. (The file php.ini and its enclosing folder etc belong to the OS, and, by default, cannot be modified by any non-super user. Hence the permission change.)
$ chmod 777 php.ini
- In this step, we’ll configure PHP with the three most familiar MySQL database interfaces: PDO, MySQLi, and MySQL. Launch emacs on php.ini to start.
$ emacs php.ini
- First, find the entry pdo_mysql.default_socket, which might appear at or around line 986. In Mac OS X, version 10.8.x, the line looks like
pdo_mysql.default_socket = /var/mysql/mysql.sockand in version 10.9.x, it looks likepdo_mysql.default_socket =In both cases, the entry needs to look likepdo_mysql.default_socket = /tmp/mysql.sock
- Do the same for mysql.default_socket and mysqli.default_socket. Both should be modified to look like
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock - Save the file. Type control + x s. That is, hold the control key down and simultaneously type x followed by s.
- Exit emacs. Type control + x c: hold the control key down and simultaneously type x followed by c.
- Change the permissions on php.ini back to 444.
$ chmod 444 php.ini
- Restart the web server.
$ apachectl restart
- Stop MySQL.
$ /usr/local/mysql/bin/mysqladmin -u root -p shutdown
- Rescind the super user role.
$ exit
- And finally, a note on character sets. If you know — or even think — you might work with characters outside the English language, then it’s a good idea to set your MySQL server, database, client, and connection character sets now. Create a file called my.cnf and place it in /etc. In it, put the following:
[mysqld] collation-server = utf8_unicode_ci init-connect = 'SET NAMES utf8' character-set-server = utf8
- Log back in to MySQL and type status once you’re logged in. Your Server, Db, Client, and Conn settings should be set to utf8.