In the previous tutorial of this series, we have configured Apache and PHP and thus we are able to run
.php files in our local server. As a follow up, we are now going to install and set MySQL up which we will be using for the database.
Let’s get started.
Recommended Reading: Install PHP, Apache, And MySQL In Mac Without MAMP
Fortunately, MySQL comes in a form of
.pkg installer that provides an easy step-by-step instruction. Download the package from this page, and make sure you grab the the DMG Archive version, which could be either Mac OS X 10.7 (x86, 64-bit), DMG Archive or Mac OS X 10.7 (x86, 32-bit), DMG Archive if you are running on 32 bit machine.
Launch the DMG package. And you should find three files as shown in the following screenshot.
Install all three. Then, after they are all completed, open System Preference, and navigate to the MySQL pane.
Turn MySQL Server on, and tick Automatically Start MySQL Server on Startup.
At this point, MySQL is running. But, OS X searches a different directory to find MySQL socket,
mysql.sock, which causes the Warning: mysql_connect():  No such file or directory error when trying to connect PHP to MySQL.
To solve this, we will create a symbolic link (symlink) in the directory where OS X expects to find the MySQL socket.
ln -s /tmp/mysql.sock /mysql/mysql.sockcommand.
Then we need to create password for
root user. In Unix terminology, the root user is the one who has all administrative access. Type the following command in Terminal to set the password:
mysqladmin -u root password new_password
Change the “new_password” with the password of your choice.
Now, we need to find a way to manage MySQL. The popular way for doing this would be using a web-based application such as phpMyAdmin. But, I’m not quite fancy with phpMyAdmin User Interface, and the installation process (to me) is rather complicated.
I found a good alternative, a lovable native OS X application named Sequel Pro. Grab the installer here, put it in the Application folder, and launch it.
In this tutorial, we are going to connect to MySQL via the socket file. So, let’s head over to the Socket tab, and enter the following information:
Click the Connect button.
Once you are connected to the MySQL, you can create, modify, and delete databases as well as creating new MySQL users. In the following example, as shown below, I’ve created a database named wordpress for my WordPress site.
In this tutorial, we have done configuring MySQL. Now, you have a fully functioning local server for developing PHP-based website in Mac. In the next part and last part, we are going to show you how to custmize the localhost. So, stay tuned.