XAMPP MySQL not starting on macOS

XAMPP MySQL not starting on macOS

XAMPP is a great tool for web developers who need to run or test web applications locally on their own computer. Unfortunately, because it runs applications on the LAMP stack, conflicts can happen, causing certain applications on XAMPP to be unable to run.

In this article, we will be exploring what you can do if XAMPP’s MySQL service does not run on a macOS platform.

  1. The problem
  2. Possible causes and fixes
    1. MySQL server conflict
    2. Killing existing MySQL processes using Terminal
    3. Changing MySQL’s port number
  3. Conclusion

1. The problem

If all of your XAMPP server programs are running except MySQL Database (like the below picture), then you are encouraged to read this article to find possible causes and solutions for your problem.

MySQL is not starting in XAMPP
MySQL is not starting in XAMPP.

In your XAMPP control panel, you might see the following text, where MySQL database is getting stuck and just cannot start:

Stopping all servers...
Stopping Apache Web Server...
/Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh : httpd stopped
Stopping ProFTPD...
Checking syntax of configuration file
/Applications/XAMPP/xamppfiles/proftpd/scripts/ctl.sh : proftpd stopped
Restarting all servers...
Starting MySQL Database...

2. Possible causes and fixes

So, what might be causing the error described above?

a. MySQL server conflict

On your macOS, you might have multiple instances of MySQL servers running. This can be caused by other applications (for e.g. SQL Workbench) running their own instances of MySQL. To fix this issue, you need to stop the other instance of the MySQL server.

Here is how to do so:

  1. Go to Applications → Utilities → Activity Monitor.
  2. Select All Processes.
  3. Search for sql by using search box.
  4. You will see the mysqld process, double-click on it and press Quit.
  5. Once, done restart mysql in the manager-osx and it will run.
Removing existing mysqld processes
Removing existing mysqld processes using the Activity Monitor.

b. Killing existing MySQL processes using Terminal

Instead of using the Activity Monitor, you can also find and close existing mysqld processes using macOS’s Terminal.

Note: To run the following commands, you will need to be able to log in as a root user on your macOS. Here’s a guide (by Apple) on how to do this: https://support.apple.com/en-us/HT204012.

  1. Open Terminal, paste this command: sudo su; and type in your password.
  2. Then copy and insert this next command: ps aux | grep mysql. This will show you the processes with mysql in its name.
  3. After getting processes, you need to get the process ID of the processes named mysql. In my case, the process is named _mysql, so I need its process ID, which is 362 (highlighted below).
root              8006   0.0  0.0 408628336   1648 s000  S+   11:37AM   0:00.00 grep mysql
_mysql             362   0.0  0.0 35192992   3396   ??  Ss   Sun10PM   0:21.82 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so
  1. Now, you need to kill this process, by using the following command: kill -9 {process id}, so for me the final command will be: kill -9 362.
  2. Restart MySQL in manager-osx and you will be good.

Tip: If you have multiple mysql processes and don’t know which want to stop, you can also stop ALL MySQL processes with sudo killall mysqld.

If you are unable to restart MySQL after, you can also try this command to directly start XAMPP’s MySQL server:

$ sudo /Application/XAMPP/xamppfiles/bin/mysql.server start

Article continues after the advertisement:


c. Changing MySQL port number

When starting XAMPP’s MySQL, if it says that it cannot connect to the port number, then changing it to a new one will help.

XAMPP cannot bind to port 3306
XAMPP cannot bind to port 3306.

To change port number, follow the instructions below.

Note: To change port number in the config file, you will need to be able to log in as a root user on your macOS. Here’s a guide (by Apple) on how to do this: https://support.apple.com/en-us/HT204012.

  1. Choose MySQL Database in manager-osx and click Configure.
  2. Change the port number to a new one, for example: 3307.
Changing the port of the MySQL service
The Configure window for XAMPP’s MySQL service.
  1. Click Open Conf File and change the port number in the file.
  2. Close the config file and click OK.
  3. Relaunch manager-osx.

The highlighted portion of the config file below is where you change the port number:

my.cnf

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /Applications/XAMPP/xamppfiles/var/mysql) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password	= your_password
port		=3306
socket		=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

Now, you are good to go.

3. Conclusion

As with the other articles on the blog, we’d love if you leave a comment below, especially if you:

  • Find any errors in this article.
  • Find any XAMPP MySQL issues that are not described in this article.

Your comments will add on to the information that is already here, and help other future readers!

Leave a Reply

Your email address will not be published.

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.