Installing and running MySQL on macOS with errors resolved

Akansha Jain
4 min readApr 24, 2018

--

This article is based on macOS High Sierra version: 10.13.4 and hopefully can work for all MacBooks having OSX+ version.

  1. Download latest .dmg file for MySQL Community server here.

During installation you must give a root password, that’s important, remember it. We will use it later.

2. Follow the detailed installation instructions given in documentation.

When installing using the package installer, the files are installed into a directory within /usr/local matching the name of the installation version and platform. For example, the installer file mysql-5.6.41-osx10.8-x86_64.dmg installs MySQL into /usr/local/mysql-5.6.41-osx10.8-x86_64/ .

3. After successful installation go to System Preferences and search mysql

when you open that, you will see the mysql server is already running

Now, this is one way to start and stop the mysql server manually. If you are looking to do the same using command prompt then follow bellow steps.

4. Open terminal and type

Pandas-MacBook-Air:~ akanshajain$ mysql.server start

You’ll probably get error “-bash: mysql.server start: command not found” or something similar. This is because the path(/usr/local) where the mysql is being installed is not written in the .profile or .bashrc (contains a series of configurations for the terminal session).

5. To solve above error, without figuring which of

‘~/.bashrc’, ‘/etc/profile’, ‘~/.bash_profile’

should be edited, the easiest way is to type

Pandas-MacBook-Air:~ akanshajain$ sudo nano /etc/paths

and add the path(s) you want here, one per line. For our installation we’ll add two mysql paths as shown in figure.

/usr/local/mysql/bin consists:

/usr/local/mysql/support-files consists:

6. Now restart your terminal and again type

Pandas-MacBook-Air:~ akanshajain$ mysql.server start

Now, you may probably get permission denied error, which looks like this.

7. Don’t worry this is just a permission error and can be easily solved by writing sudo(gives super user access) in front of the command like this:

Pandas-MacBook-Air:~ akanshajain$ sudo mysql.server start

Yay!! We did it. Now, to stop mysql server, type

Pandas-MacBook-Air:~ akanshajain$ sudo mysql.server stop

You can also restart an already running server by typing

Pandas-MacBook-Air:~ akanshajain$ sudo mysql.server restart

To check current server status, type

Pandas-MacBook-Air:~ akanshajain$ mysql.server status

8. Type the following command and enter the password for root that I asked you to remember in the start to enter mysql console as a root user.

Pandas-MacBook-Air:~ akanshajain$ mysql -u root -p

9. Let me give you a little demo of structured query language. Type quit to exit mysql console.

mysql> CREATE DATABASE mynewdb;mysql> use mynewdb;mysql> create table pet (name VARCHAR(20), owner VARCHAR(20), birth DATE, death DATE);mysql> show tables;

10. If you are facing other errors related with PID, or errors in starting/stoping the server, which can be caused by broken installation. This one is master hack. Just remove folder /usr/local/var/mysql and then reinstall mysql again brew reinstall mysql. (Note homebrew should be pre installed for this to work). Also, if you get access denied error when logging in as root, which is probably because root password being not correct. Then run below commands, it will reset the password, and you can run Step 8 again.

Pandas-MacBook-Air:~ akanshajain$ mysql
or
Pandas-MacBook-Air:~ akanshajain$ sudo mysql
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

In this article we successfully installed and run mysql on macOS covering all the possible errors that one may face during this process. I hope it helps you. You can follow me on Twitter, my work on Github, and connect professionally with me on LinkedIn.

______________
Edit 1: If you still aren’t able to install it correctly, go through the comment section of this post, you might find your problem and solution there. Thanks for contributing in the comments fellow readers!

--

--

Akansha Jain

Senior Data Scientist, Builder.ai | Master’s in Data Analytics at Indian Institute of Information Technology & Management, Kerala.