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.

Are you looking at getting XAMPP MySQL to work on Windows instead? I’ve also wrote a guide for getting XAMPP Apache working on macOS. Do click on these aforementioned links if they are what you need instead.

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

If you try to access phpMyAdmin via http://localhost/phpmyadmin with Apache started (and without starting the MySQL module), you will also see the following error screen:

phpMyAdmin connection refused
phpMyAdmin cannot be connected to without starting MySQL.

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!

There are 13 comments:

  1. Hi, every time I kill a process a new one is created too. I deleted MySQL Workbench and other mysql applications but it is still running. I can not change my port number. What can I do?

    1. Hi Ayca, do you have another process running called mysqld_safe? If you have that, try terminating that first before terminating mysqld. Otherwise, can you have a look at the Activity Monitor and tell me which is the parent process of your mysqld process which keeps respawning?

  2. Thank you Azat.

    I am using XAMPP 8.2 and also did try 7.3.25, all the same.

    I am new in WebDevelopent and try now learning the Backend with PHP and SQL. Apache and FTPD are running, same pic as you show at the beginning.

    I am using a book to teach myself and this book uses XAMPP with which I cannot get to run the SQL.
    I did also try MAMP which runs the SQL from the beginning onward.

    I stop MAMP when starting XAMPP and then do not have a 2nd sql process, so far is OK.

    My problem may be much more basic because the error message tells:
    mysqli::real_connect(): (HY000/2002): No such file or directory

    It seems I oversee very basic settings but I could not find working instructions in the last 4 days.

    I did also try to install XAMP on a fresh MacBook Air where is nothing installed besides GIT, and the same result there.

    1. Hi Anna, check if you have any other programs installed on your computer that could be restarting the process. For example, if you have MySQL Workbench installed, that application may be constantly restarting the mysqld process.

  3. Hi.
    Thank you very much, I haven’t reid yet but your tips might fix my recent problem that the MySQL Server of Xampp does not start (anymore) on my Mac with M1 CPU.
    But as you are asking for additional problems, here you go:
    When (!) the MySQL server still run, I had several PHP-Pages with SQL commands which worked fine in Xampp environments on Windows (10), but did not work properly on the Mac. Eg.the page did connect with the database and could read the datasets but was unable to write new datasets into the database…
    Any idea reagarding reason and solution?
    Thank you very much!

    1. Hello, Frank, can you describe problem more deeply, like what kind of errors XAMPP gives you? Maybe you can directly paste the error message?

Leave a Reply to John Cancel reply

Your email address will not be published. Required fields are marked *

Note: You can use Markdown to format your comments.

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.

This site uses Akismet to reduce spam. Learn how your comment data is processed.