I’m having trouble with MySQL on my MacBook M2 chip. After setting up XAMPP yesterday, MySQL started acting weird. It keeps switching between running and stopped states without me doing anything. I removed XAMPP completely and installed it again but the problem got worse. Now MySQL won’t shut down at all and stays running constantly.
The connection test in MySQL Workbench shows everything is fine:
- Server: 127.0.0.1
- Port: 3306
- Username: root
- SSL: disabled
- Status: Connection successful
But when I try making a new database called ‘projectdb’, I get this error:
Error Code: 1006. Can't create database 'projectdb' (errno: 2 "No such file or directory")
I can connect to MySQL just fine but creating databases fails every time. Has anyone seen this issue before on M2 Macs? What could be causing the file system error when the connection works perfectly?
This looks like a MySQL configuration issue rather than an M2-specific problem. The error suggests MySQL cannot access its designated data directory path. Check your MySQL configuration file (my.cnf or my.ini) and verify the datadir parameter points to a valid location. Sometimes XAMPP reinstallation changes these paths without updating the configuration properly. You can find the current datadir setting by running SHOW VARIABLES LIKE 'datadir'; in MySQL Workbench. If the path doesn’t exist or is inaccessible, you’ll need to either create the directory structure manually or update the configuration to point to the correct location. I’ve seen this happen when XAMPP gets installed in a different location during reinstallation but the configuration still references the old paths.
looks like mysql service might be corrupted from the xampp mess. try completely uninstalling mysql first using homebrew if you have it installed there too - sometimes multiple mysql installations conflict on m2 macs. then do a clean xampp install and make sure only one mysql instance is running. the errno 2 usually means mysql cant write to disk somewhere.
Had this exact same issue on my M2 MacBook Pro about six months ago. The problem turned out to be MySQL data directory permissions getting corrupted during the XAMPP reinstall process. What fixed it for me was manually recreating the MySQL data directory with proper ownership. First, I stopped MySQL completely using the terminal with sudo /Applications/XAMPP/xamppfiles/bin/mysql.server stop. Then I had to check the MySQL configuration file to see where the data directory was supposed to be located - usually it’s in /Applications/XAMPP/xamppfiles/var/mysql/. The directory existed but had wrong permissions. I backed up the existing mysql folder, deleted it, and let MySQL recreate it on the next startup. After restarting XAMPP, database creation worked normally again. The M2 chip seems particularly sensitive to permission issues with XAMPP installations.