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
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.
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:
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:
- Go to Applications → Utilities → Activity Monitor.
- Select All Processes.
- Search for sql by using search box.
- You will see the mysqld process, double-click on it and press Quit.
- Once, done restart mysql in the manager-osx and it will run.
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.
- Open Terminal, paste this command:
sudo su
; and type in your password. - Then copy and insert this next command:
ps aux | grep mysql
. This will show you the processes with mysql in its name. - 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
- 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
. - 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
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.
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.
- Choose MySQL Database in manager-osx and click Configure.
- Change the port number to a new one, for example: 3307.
- Click Open Conf File and change the port number in the file.
- Close the config file and click OK.
- 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!
Muito obrigado! Sua ajuda foi de grande valia.
Sucesso!!
Tyvm !
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?
Hi Ayca, do you have another process running called
mysqld_safe
? If you have that, try terminating that first before terminatingmysqld
. Otherwise, can you have a look at the Activity Monitor and tell me which is the parent process of yourmysqld
process which keeps respawning?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.
Hi Martin, sorry, it looks like we missed your comment. Did you manage to find a solution to your errors in the end?
Thank you thats work
Hi, every time I kill a process a new one is created. Do you know what could happen?
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.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!
Hello, Frank, can you describe problem more deeply, like what kind of errors XAMPP gives you? Maybe you can directly paste the error message?
Thank you very much, Helped me to fix my problem!!!
Hi John, you’re very welcome :)