321

On Mac OS X v10.6 (Snow Leopard), starting MySQL gives the following error:

The server quit without updating PID file

File my.cnf

[mysqld]
port            = 3306

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 16K

pid-file=/var/run/mysqld/mysqld.pid

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chinmay
  • 4,971
  • 5
  • 23
  • 15
  • How are you starting mysql? Does the user mysql is running as have read/write access to your /var/run/mysql/ folder? – dmcnelis Feb 10 '11 at 22:52
  • 7
    running as admin user. with sudo /usr/local/mysql/support-files/mysql.server start – Chinmay Feb 11 '11 at 15:15
  • 9
    same problem. Installed mysql with brew – vrybas Nov 09 '11 at 04:42
  • 26
    same problem here. also installed with brew. – jspooner Nov 09 '11 at 19:35
  • 12
    I got this case too on my mac, and just removed the error log, like '/usr/local/var/mysql/*.err', started successfully. – Mathew P. Jones Dec 02 '14 at 02:28
  • 3
    I also got same error on mac. But i got solved it. If you are installed via .dmg file go to system preferences then click on mysql icon then click start mysql button . – Amaranadh Meda Mar 07 '16 at 15:30
  • on clicking the mysql start mysql button via system preferences pane, it doesnt start for some reason – Chaitanya Bapat Mar 29 '18 at 22:21
  • One mac, there are a variety of issues that could be the reason for this error. You can find a step by step summary to solve them here: https://medium.com/@7anac/mysql-error-the-server-quit-without-updating-pid-file-ce320ff75828 – Janac Meena May 08 '20 at 13:49

55 Answers55

306

Try to find your log file with suffix ".err". There should be more information. It might be in:

/usr/local/var/mysql/your_computer_name.local.err

It's probably a problem with permissions

  1. Check if any MySQL instance is running

    ps -ef | grep mysql
    

    If yes, you should stop it, or kill the process:

    kill -9 PID
    

    where PID is the number displayed next to the username on the output of the previous command

  2. Check ownership of /usr/local/var/mysql/

    ls -laF /usr/local/var/mysql/
    

    If it is owner by root, you should change it to mysql or your_user

    sudo chown -R mysql /usr/local/var/mysql/
    
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tombart
  • 30,520
  • 16
  • 123
  • 136
  • 28
    I had to chown to mysql user rather than my user. – Jared Aug 20 '12 at 19:13
  • 3
    worked for me. i checked the error file and said that it was becuase o file permissions. executed the chown command and worked. thanks!! – Packet Tracer Feb 26 '13 at 19:47
  • 2
    sudo chown -R my_user /usr/local/var/mysql/ worked for me at least – Bjørn Børresen Mar 21 '14 at 12:01
  • From my own experience - Be careful that after you've done the sudo chown that you don't currently have some mysql processes running under another user or root. ps -ef | grep mysql will validate that you have nothing running - otherwise you won't be able to start it. – Arthur Frankel May 22 '14 at 14:41
  • sudo chown -R mysql /usr/local/var/mysql/ this worked like a charm for me. – shehata Aug 12 '14 at 02:08
  • The reason this was useful for me was that I was not able to control mysql from the native install. I installed via Homebrew instead, then was able to use this answer to kill all other (zombie) processes left over by Xampp. Thanks! – jffgrdnr Aug 13 '14 at 19:33
  • +1 for mentioning permissions. For me it was `chown -R mysql:mysql /var/lib/mysql` (on Linux not Mac) – groovenectar Aug 19 '14 at 13:13
  • Mysql failed to start after I migrated it to a new machine. The chown command fixed it. I had to migrate to a new id on the destination machine. The change in the id most likely caused the problem. – curt Dec 02 '14 at 17:46
  • chown to myself fix the pid problem. – yangsibai Apr 29 '15 at 10:21
  • killing the process via kill -9 PID worked for me, thanks – bonbonez Apr 03 '16 at 20:30
  • This worked for me. In my case it was caused by running "sudo mysql.server start" instead of mysql.server start. This changed the owner of the pid file (mentioned in the error message) to _mysql. I noticed that every other file in there was owned by me, so I simply changed the owner of the PID file to myself and ran "mysql.server start". – Joe Edgar Jun 26 '16 at 00:31
  • this line is what worked for me: "sudo chown -R mysql /usr/local/var/mysql/" it had been set to root. I'm not sure how it was changed but possibly by a different development environment I had recently set up locally. – Dennis Plucinik Aug 15 '17 at 16:52
  • 2
    Total life saver. My only observation is the file path to mysql folder may vary. – ALisboa Apr 13 '18 at 19:26
  • The chow helped me1 – Bogdan M. Jun 05 '18 at 15:29
  • For me, it was caused by a permissions problem, but not file owner, selinux=enforcing try sudo setenforce 0 – Joe Jadamec Jun 19 '20 at 02:15
209

Follow the instructions from brew install mysql.

Set up databases to run as your user account with:

For MySQL 5.x:

unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

To set up base tables in another folder, or use a different user to run mysqld, view the help for mysqld_install_db:

mysql_install_db --help

And view the MySQL documentation:

For MySQL 8.x:

unset TMPDIR
mysqld --initialize-insecure --log-error-verbosity --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

Make sure the data directory /usr/local/var/mysql above is empty. Back it up if necessary.

To run as, for instance, user "mysql", you may need to sudo:

sudo mysql_install_db ...options...

Start mysqld manually with:

mysql.server start

Note: if this fails, you probably forgot to run the first two steps up above

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
svs
  • 2,425
  • 1
  • 14
  • 10
  • I also had to run the following two commands: You should reload mysql: launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist – dylam Jan 28 '13 at 05:41
  • 79
    If you're repeatedly getting the same error even after following the steps from the output then delete the *.err file from the same directory as the *.pid file. http://www.mahdiyusuf.com/post/21022913180/mysql-the-server-quit-without-updating-pid-file – awhie29urh2 Feb 20 '13 at 22:07
  • http://madebyhoundstooth.com/blog/install-mysql-on-mountain-lion-with-homebrew/ this is also a good reference. – Brian Feb 22 '13 at 06:11
  • 6
    I tried following these instructions a million times but never got it to work. I tried to "cheat" by not cleaning up all the things brew doctor warned me about since I thought they didn't make a difference. In the end, cleaning up and following brew doctors advice made it possible to run through the setup described above. So a note to anyone else passing by; don't try to cheat the brew doctor and think you know better! – span Mar 26 '13 at 21:04
  • 10
    I still have a bunch of things wrong in when I brew doctor and adding write permission to my own user did the trick. `sudo chown -R your_user /usr/local/var/mysql/` just as @Tombart 's answer :) – GabLeRoux Jun 13 '13 at 04:28
  • FYI doesn't work on Mavericks using brew and Mysql Ver 14.14 Distrib 5.6.16 – Joel Joel Binks Feb 22 '14 at 01:57
  • If the setups above is not working. Please trying deleting the .err file (but in the same terminal session) then run the `mysql.server start` command – Chan Apr 02 '14 at 02:31
  • It might be important to back up your db, clear out all older MySQL versions you currently have and follow the install directions here https://coderwall.com/p/os6woq which also coincides with this solution. – Ransom Oct 29 '14 at 15:45
  • I had this problem as well, but the solution in this answer did not work. Ultimately, the only thing that worked was the answer a bit farther down, namely deleting the error file /usr/local/var/mysql/.local.err – fraxture Mar 04 '15 at 09:46
  • 1
    @countfloortiles Yes! Removing the error file did it. :-) – ott-- Oct 24 '15 at 22:27
  • 8
    The `mysqld_install_db` command gives me the error `mysql_install_db: [ERROR] unknown variable 'tmpdir=/tmp'` – Snowcrash Nov 16 '15 at 22:11
  • 1
    Correct answer? Not necessarily. If the problem is related to permissions, they can have changed because another operation that doesn't have relation with the mysql installation. The question isn't about installation. – mold Jan 24 '16 at 00:54
  • @svs (mysql_install_db --verbose --user=`sudo's login` --basedir="/a/.../mysql_x" --datadir="/a/.../mysql_x/data" --tmpdir="/tmp") ; I am not sure does paths should have double quotes "path" for example? And it will be ok if to set path to another volume non-home one? After reboot I am facing pid file error as well right now X( Does it worth to create another mysql user as official readme says or using sudo for everything is pretty fine? Please give me a tip – user390525 Mar 18 '16 at 08:50
  • 1
    @TaylorFoster allow me to disagree. The command fails `mysql_install_db: [ERROR] unknown variable 'tmpdir=/tmp'` tried running ` mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir="/tmp"` – FooBar Oct 26 '18 at 13:45
  • 2
    `mysql_install_db` is removed in mysql 8.0 – Itachi Jul 15 '19 at 06:38
  • `/usr/local/mysql/support-files/mysql.server restart` worked for me – snehm May 26 '20 at 09:31
  • The only answer that worked. Thanks much. – Tushar Gupta Apr 08 '21 at 12:26
125

I had the same issue on my Mac machine (correctly followed all the installation steps suggested by brew install).

Deleting the error file fixed it for me:

sudo rm -rf /usr/local/var/mysql/dev.work.err (dev.work is my hostname)

This worked because dev.work.err was owned by _mysql:wheel instead of my own username. CHOWN-ing the error file would have probably fixed it as well.

ukliviu
  • 3,136
  • 1
  • 24
  • 30
  • 2
    This solved my problem too, after rebooting mysql couldnt working anymore, giving me this same issue, but removing the error log which was owned by _mysql:admin solved the issue – user980085 Aug 02 '13 at 12:03
  • 5
    This seemed to be the most helpful, made me realize that I should not be starting this service with SUDO but running it under my own user account. – Bnjmn Aug 13 '13 at 00:16
  • 3
    This is a pretty good answer for those who have installed MySQL using Homebrew – Stephane Paquet Jan 19 '14 at 20:32
  • After weeks of trying different things, when I removed the error file everything started working. Thanks – D.F. Jun 19 '14 at 01:49
  • I didn't have to delete it, just chown it back to my account, because somewhere _mysql account took it over. – Sammy Larbi Aug 01 '14 at 20:57
  • This was the issue for me as well. Thanks. – Jamesy Dimmick May Nov 15 '15 at 19:15
  • OMG! some sort of unable to write to /path/to/errorlog.err output would be way to much to ask. – Brad Kent Jan 06 '16 at 22:00
  • Worked perfectly for me! – alexpirine Feb 29 '16 at 21:21
  • I tried many things and this was the first one to work for me. This is good if you previously had mysql installed and reinstalled it, since that file was owned by the previous installation of mysql. – jacurtis Jul 16 '17 at 21:28
104

After rebooting I had the same issue. Here is how I fixed it:

sudo chown -R _mysql /usr/local/var/mysql
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sam Ruberti
  • 1,549
  • 1
  • 12
  • 10
  • thanks a lot - don't forget to backup stuff though, just in case you're messing w/ the permissions – m02ph3u5 Mar 10 '14 at 12:13
  • Thanks. I was having an issue with Lampp in Ubuntu. I copied the entire lampp folder from /opt to a new server. When I tried to start up mysql I got a message: The server quit without updating PID file. Go to lampp/var/ and do chown -R mysql mysql/ That worked for me! – David Morabito Sep 11 '14 at 03:20
  • 10
    On El Capitan this worked: `sudo chown -R _mysql /usr/local/mysql/data` – Justin Oct 17 '15 at 03:57
  • @Justin; this answer also worked on El Capitan for me – Ashwani Agarwal Mar 03 '16 at 11:48
  • @Justin i recovered my password to vote your answer on El Capitan! – xuanhung2401 Oct 01 '16 at 00:26
  • This didn't work for me. It just inserted a lot of permission denied errors, like this one: `/usr/local/Cellar/mysql@5.7/5.7.23/bin/mysqld_safe: line 144: /usr/local/var/mysql/Victors-MacBook-Air-2.local.err: Permission denied` – Victor Sep 26 '18 at 07:05
  • /tmp/ folder - mysqlx.sock* files getting created with 'mysql' as a owner it worked for me after deleting those entries – Ram Feb 09 '19 at 00:47
  • note that if you installed using homebrew, command should be: sudo chown -R _mysql /opt/homebrew/var/mysql – Onur Çevik Apr 06 '22 at 11:50
35

This worked for me...

Check all of the MySQL processes running:

$ ps aux | grep mysql

USER     PID    %CPU  %MEM 
_mysql   5970   0.0   0.4 ...

Then kill all the processes listed from the above command using the following:

$ sudo kill -9 [PID]

Replace [PID] with the individual PID from the list above, e.g. 5970.

Do that for all of the lines you see with the first command.

Then you can startup your MySQL server again:

mysql.server start
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
mikoop
  • 1,981
  • 1
  • 18
  • 18
35

Try to remove the ib_logfile0 and ib_logfile1 files and then run MySQL again:

rm /usr/local/var/mysql/ib_logfile0
rm /usr/local/var/mysql/ib_logfile1

It works for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3890355
  • 1,010
  • 13
  • 13
31

This error can occur when trying to start MySQL after it was improperly shut down.

  1. Take a look at the MySQL error log file. If it mentions something like "Check that you do not already have another mysqld process using the same data or log files.", then you need to properly shutdown that process.

  2. See what process MySQL is running on. Use the command lsof -i:3306 (the default port number for MySQL is 3306).

    Your output should look like this:

    COMMAND   PID      USER  FD   TYPE  DEVICE             SIZE/OFF NODE NAME
    mysqld   4249  username  17u  IPv4  0x7843d9d130469c0b      0t0 TCP  localhost:mysql (LISTEN)
    
  3. Terminate the process running mysql: kill -15 4249

    Kill -15 sends a signal to the process to free up any resources it is locking and terminate the process after.

  4. Now MySQL should start up with no problems: mysql.server start

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cosbor11
  • 14,709
  • 10
  • 54
  • 69
  • This still works for me in High Sierra, for whatever that's worth. – Jonathan Stegall Feb 01 '18 at 14:23
  • The `lsof` command may require sudo: `sudo lsof -i:3306`. Otherwise, the output may be empty. – Peter Mortensen Oct 30 '21 at 03:10
  • I have been researching for hours. NONE of the solutions worked, except this one. One of the reasons it didn't work earlier for me is that I didn't think I needed to disconnect from my remote server (via ssh tunnel) to clear the error. But when I finally gave up and closed my ssh tunnel to the remote server, the issue resolved itself. – JessycaFrederick Feb 07 '22 at 23:15
  • I could not find the PID using `ps -ef | grep mysql` as stated above, but this one worked for me, thanks! – Jk33 Apr 15 '22 at 02:58
28

⚠️ This will erase your data, so make sure it's backed up first.

If no one answer helped you, just remove folder /usr/local/var/mysql and then install MySQL again using brew reinstall mysql.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3890355
  • 1,010
  • 13
  • 13
  • 16
    WARNING thats means erase all databases. – theredled Dec 01 '18 at 22:20
  • 1
    I install a higher version mysql before, than I install mysql5.7 and this problem occurs. Just remove /usr/local/var/mysql and `brew reinstall mysql@.57` solve it. – Pegasus Apr 01 '19 at 08:59
  • 1
    Move the dbs under /usr/local/var/mysql to another folder first. After installation and start mysql service successfully, try to move needed db back. – civic.LiLister Feb 04 '20 at 19:59
  • After trying several ways, this answer works for me. Removing `/usr/local/var/mysql` folder and reinstall `mysql` via brew works. – Anh Tran Nov 29 '22 at 09:04
24

My error file told me also that the port may be being used by another process, but simply running sudo mysql.server start fixed the issue for me.

jaredsmith
  • 7,306
  • 3
  • 20
  • 31
  • 2
    yeah... this worked for me too... and nothing above worked – Prashant Sep 27 '16 at 06:39
  • I was following instructions I'd read somewhere the way to start MySQL on a Mac is 'sudo /usr/local/mysql/support-files/mysql.server start'. That produced the error "the server quit without updating pid file", and that's how I got to this page. After trying numerous answers, I found 'sudo mysql.server start', and it worked. Thanks. – rodmclaughlin Aug 21 '18 at 19:25
18

For me the fix was simple.

top

showed that mysqld was already running.

sudo killall mysqld 

then allowed the process to start.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Luke Madhanga
  • 6,871
  • 2
  • 43
  • 47
15

I recently came across this issue, however it was working before, then stopped.

This was because I initially started mysql.server as root instead of myself.

The fix was to delete the err log file (which was owned by _mysql). Starting it again got it passed.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Roland Parnaso
  • 151
  • 1
  • 3
  • Thanks! I had the same issue searching for an hour then came across your answer. – FLY Sep 23 '14 at 08:29
13

For me I had to reinstall MySQL:

brew reinstall mysql

And then the below to have launchd start MySQL now and restart at login:

brew services start mysql
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sumit
  • 15,003
  • 12
  • 69
  • 110
11

The solution that worked for me was here: Can't create PID file on MySQL server, permission denied

Changing some of my permissions seemed to do the trick. I'm running a mid-2012 MacBook Air with Mac OS X v10.8.2 (Mountain Lion) and MySQL was installed with Homebrew.

chmod 0755 /var
chown root:wheel /var/tmp
sudo chmod 0771 /usr/local/var/mysql/*
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gabe
  • 2,117
  • 1
  • 16
  • 13
9

This worked for me:

Note: This a hard reinstall. Use when all other options have been exhausted.

On a Mac with Homebrew:

List all instances of MySQL that exists by running

brew services

Remove each instance by running

brew uninstall <instance_name>

Delete the MySQL directory in /usr/local/var/mysql:

rm -rf /usr/local/var/mysql

Reinstall MySQL using Homebrew:

brew install mysql
brew install mysql@<version> #Optional

Rerun mysql.server start:

mysql.server start
Dave Kalu
  • 1,520
  • 3
  • 19
  • 38
8

I'm using

I installed MySQL using Homebrew ('brew install mysql'). It installed a couple of dependencies and then MySQL.

When I tried to start it up,

mysql.server start

Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/west.local.pid).

I ran this command,

/usr/local/Cellar/mysql/5.5.25/scripts/mysql_install_db

and MySQL works.

Please take note that you need to run mysql_install_db from the top level of the MySQL directory (e.g., usr/local/Cellar/mysql/5.5.25). Running it directly within the /scripts directory does not give it enough context for it to run.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
westonplatter
  • 1,475
  • 2
  • 19
  • 30
8

I had this problem while trying to brew upgrade on Mac OS X v10.7.5 (Lion).

Unfortunately MySQL was also upgraded to 5.6.10 from 5.5.14. I tried the new version, but it did not work.

I decided to go back to my old setup and did a

brew switch mysql 5.5.14

This did not solve the problem. Elsewhere I read and did this, voila! All was back :)

cd /usr/local/var/mysql
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cenk
  • 1,389
  • 14
  • 27
8

With the help of a few answers posted here, I was able to find the issue

First I run

sudo -i

So I could have root access.

Then I deleted the xxxx.err file:

rm -rf /usr/local/mysql/data/xxxx.err

After I started MySQL in SafeMode,

/usr/local/mysql/bin/mysqld_safe start

It will try to start and will exit because of an error... a new xxx.err file will be created and you need to read it to see the cause of the error:

tail -f /usr/local/mysql/data/mysqld.local.err

In my case, for some reason, it was missing some folder and file inside /var/log/ folder... So I created both:

cd /var/log

mkdir mysql

touch mysql-bin.index

After the new file was created, then you need to change permissions:

chown -R _mysql /var/log/mysql

When all those steps were taken, my database started working immediately...

The key is to read the error and log and find what's is wrong...

Paulo Griiettner
  • 1,115
  • 12
  • 18
7

For me the solution was to override/correct the data directory in /etc/my/cnf.

I built MySQL 5.5.27 from source with the directions provided in the readme file:


# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> cmake .
shell> make
shell> make install
# End of source-build specific instructions

# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data

# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &

# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

mysqld_safe terminated itself without explanation. running /etc/init.d/mysql.server start resulted in the error:

"The server quit without updating PID file"

I noticed something odd in the installation instructions though. It has ownership changed to mysql for the directory "data", but not to "var"; this is unusual because for years I have had to ensure that var directory was mysql writable. So I manually ran chown -R mysql /usr/local/mysql/var and then attempted to start it again. Still no luck. But worse, no .err file in the var dir - it was in the "data" dir! so scripts/mysql_install_db sets up camp in /usr/local/mysql/var, but the rest of the application seems to want to do its work in /usr/local/mysql/data!

So I just edited /etc/my.cnf and under the section [mysqld] I added a directive to explicitly point mysql's data directory to var (as I normally expect it to be any how), and after doing so, mysqld starts up just fine. The directive to add looks like this:

datadir = /usr/local/mysql/var

Worked for me. Hope it helps for you.

SKelly
  • 71
  • 1
  • 1
7

If your system has multiple version of MySQL then you are likely going to hit this PID error:

We can begin with killing all MySQL processes:

sudo killall mysqld

Go to /usr/local and choose which MySQL version you want to have, and then provide the MySQL permission to that. In my case I needed version 8.

sudo chown -R mysql mysql-8.0.21-macos10.15-x86_64

Go to the folder /usr/local/mysql-8.0.21-macos10.15-x86_64 and start the SQL server:

sudo ./mysql.server start (Enter your laptop password)

If it gives the below output... the PID issue is solved

sudo ./mysql.server start

Starting MySQL
.. SUCCESS!
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SANGEETHA P.H.
  • 1,059
  • 11
  • 7
5

It seems that the MySQL process is running, hence you are unable to use the port. You can check the running MySQL process using following command:

ps auxf | grep mysql

If you get any MySQL process, kill that process ID using kill -9 PID and then try to start MySQL.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
colin2328
  • 61
  • 1
  • 4
5

Start MySQL in safe mode:

/usr/local/mysql/bin/mysqld_safe start

Or on the Mac, end any mysql or mysqld task (or other) in your Activity Monitor application.

Or check you error by

tail -f /usr/local/mysql/data/XXXXX-XXXXX-Pro.local.err
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78
4

Somehow I screwed up my permissions on Mac OS X v10.11 (El Capitan) and decided to reinstall MySQL from scratch.

I use Homebrew on El Capitan and decided to reinstall:

brew uninstall mysql
sudo rm -rf /usr/local/var/mysql
brew install mysql
mysql.server start # ... SUCCESS

The file permissions on a fresh install changed from _mysql to include my username:

ls -alh /usr/local/var/mysql
drwxr-xr-x   22 lfender  admin   748B Mar 22 09:58 .
# ... etc.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
4

In my case, the error happens due to the accessing problem of the error log file.

The following two commands help me address the problem.

sudo chown <user> /usr/local/var/mysql/<my-host-name>.err
sudo chmod 666 /usr/local/var/mysql/<my-host-name>.err
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
FrankSu
  • 331
  • 1
  • 4
  • 10
4

What's the error log saying? I got this error, and it ended up being an old invalid setting in the my.cnf file, which the MySQL error log indicated. If not a bad configuration setting, the error log should at least point you in the right direction.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian Ray
  • 1,256
  • 1
  • 13
  • 19
3

I had the same problem. Moving my /etc/my.cnf file worked for me. I got the information here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nealv
  • 6,856
  • 8
  • 58
  • 89
3

I had the same issue. For me it was doing a brew remove while having a previous install of the mysqld running. It seems Homebrew (brew) does not stop a service before uninstalling.

After checking the .err file I saw the logged error that another copy of MySQL may be running, after terminating the old service. I was then able to restart the new MySQL install.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nudge
  • 31
  • 2
  • Yes, check error logs. In my case, I ran `ls -latr /usr/local/var/mysql/` to find the latest modified file, which included the error log, then `tail -50 name.err` to see the error, which was a problem in config. – mahemoff Sep 26 '13 at 08:54
  • thanks god, you were right. I used `ps aux | grep mysqld` and then terminated the process with `kill -9 [proccessid]` and the server started successfully – Sagish Oct 08 '13 at 06:56
3

Check if you have space left in your drive. I got this problem when no space left in my drive.

thavan
  • 2,409
  • 24
  • 32
3

Simple...

Fix the 2002 MySQL socket error.

Fix the looming 2002 socket error – which is linking where MySQL places the socket and where OS X thinks it should be. MySQL puts it in /tmp and OS X looks for it in /var/mysql. The socket is a type of file that allows MySQL client/server communication.

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Well done :) This helped me a lot!

I took this guide from the guys on http://coolestguidesontheplanet.com/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

I hope this works for you.

After checking the error log, I found this:

120309 17:42:49 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
120309 17:42:50 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
120309 17:42:50 [Warning] You need to use --log-bin to make --binlog-format work.
120309 17:42:50 [Note] Plugin 'FEDERATED' is disabled.
120309 17:42:50 InnoDB: The InnoDB memory heap is disabled
120309 17:42:50 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120309 17:42:50 InnoDB: Compressed tables use zlib 1.2.3
120309 17:42:50 InnoDB: Initializing buffer pool, size = 16.0M
120309 17:42:50 InnoDB: Completed initialization of buffer pool
120309 17:42:50  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name /usr/local/mysql/data/ib_logfile0
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
120309 17:42:50 mysqld_safe mysqld from pid file /usr/local/mysql/data/lu1s.local.pid ended

And to solve it, I gave ownership rights to the entire mysql folder:

cd /usr/local
sudo chown mysql mysql
sudo chown mysql mysql-5.5.21-osx10.6-x86_64
sudo chown _mysql mysql
sudo chown _mysql mysql-5.5.21-osx10.6-x86_64

Then (you can do it command-line too), I applied the permissions (once I gave that ownership to _mysql and mysql users) to all enclosed folders from within the "get info" menu of the folder at /usr/local/mysql-5.5.21-osx10.6-x86_64 . You don't need to tho that to the alias since it's only an alias.

The name of the folder depends of the installation version of MySQL that you have.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lu1s
  • 5,600
  • 3
  • 22
  • 37
2

The problem is a permissions one. It can't start because it can't write to file mac.err because it’s owned by someone else.

Make sure the /usr/local/var/mysql folder is owned by the user that will start MySQL. If I start MySQL as jack it’s all good. However, if you start it as root, it will create a mac.err file (owned by root) file that jack can't write to, so when you try to restart it as jack it will fail.

  1. Ensure the folder and files are owned by the user running mysql.server start
  2. Make sure there's not already a mac.err or mac.pid file owned by someone else.
  3. Start is as the right user.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jack Sukerman
  • 161
  • 1
  • 3
2

Move the log file named “ib_logfile” in “/var/lib/mysql” and restart mysql. Sometimes mysql will fail because it faces difficulty updating the log file

mv /var/lib/mysql/ib_logfile* /some/tmp/folder/

You can also remove ib_logfile as it will be created automatically after mysql restart

now restart mysql server

Zangetsu
  • 1,900
  • 17
  • 25
2

Try this...

  1. Navigate to the problem's parent directory cd YOURPATH/usr/local/mysql
  2. rm -rf *.local.err (deletes file)
  3. touch YOURUSERNAME.local.pid (generates new *.local.pid file the error thrown was complaining about)
  4. 'cd' back into your project and restart MySQL using mysql.server start
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nick Sarafa
  • 986
  • 10
  • 16
  • 1
    This worked for me. Reason being, the `error.log` file was owned by "_mysql" throwing errors in the logs. Just wanted to log that incase anyone else has this issue. ```150818 19:32:06 mysqld_safe Logging to '/opt/boxen/log/mysql/error.log'. 150818 19:32:06 mysqld_safe Starting mysqld daemon with databases from /opt/boxen/data/mysql /opt/boxen/homebrew/bin/mysqld_safe: line 129: /opt/boxen/log/mysql/error.log: Permission denied``` – Donovan Aug 18 '15 at 23:35
  • This doesn't work if your problem is related to permissions, that throws the same mysql error. – mold Jan 24 '16 at 00:45
  • Worked for me as well. I also had to restart my apache (for those also using a LAMP stack). –  May 10 '16 at 16:53
2

In my case, I got this issue on a VPS and with cPanel.

I tried most of the previous answers, but without success.

  1. check where your error log is. It would be mentioned at the end of the error line.

    ERROR! The server quit without updating PID file (/var/lib/mysql/111318.vps-11.com.pid).

  2. Open that file (/var/lib/mysql/111318.vps-11.com.err) and check the bottom for the latest lines. In my case, there is

    [ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/db' is marked as crashed and should be repaired

  3. How solve this: Recovering and fixing the table indexes by command:

    [~]# myisamchk -r /var/lib/mysql/mysql/db.MYI

    MySQL is not running

  4. (Re)Start your MySQL server

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sadee
  • 3,010
  • 35
  • 36
1

I was trying to reinstall MySQL, and I actually forgot to stop the server from my old install. To solve that, ps -ax | grep mysql and kill [whatever PIDs]. But, then again, it's different for everybody. Like the other answers said, go to /usr/local/var/mysql/ and check your .err log file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Oliver
  • 2,182
  • 5
  • 24
  • 31
  • This was my problem also - in the log file I was getting "Unable to lock ./ibdata1 error: 35". Killed all processes > restart and SUCCESS! – Michael Nelles Sep 06 '18 at 22:26
1

In my case, when I tried to start MySQL, I received the same error: The server quit without updating PID file. This is what I did to fix it (using Terminal):

goto /usr/local/var/mysql
sudo rm -rf hostname.err # Delete .err file
cd /usr/local/mysql/support-files
sudo mysql.server start # Success!
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shane Zhao
  • 11
  • 1
1

Remove the pid file, then start up mysqld again.

Rick James
  • 135,179
  • 13
  • 127
  • 222
1

Delete *.err files that you find in the directory displayed in the error, create the file MySQL is complaining about, and restart MySQL.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Francisco Félix
  • 2,413
  • 13
  • 16
1

I encountered this problem after a reboot and removing all *err files.

It appeared for me that the my.cnf.d directory was missing in folder /usr/local/etc.

It created it:

mkdir /usr/local/etc/my.cnf.d

And I just copy-pasted files my.cnf and my.cnf.default located in /usr/local/etc into that directory.

Then MySQL was able to restart:

cd /usr/local/var/mysql
mysql.server start

And MySQL works.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AlUrvoy
  • 35
  • 8
  • WTF......all the error logs were leading to permissions....13 hours wasted and this is like JESUS to me...!! – ronit Jun 17 '23 at 21:32
0

This problem usually arrives when you do not have the libaio.1 library installed. Install that package first and redo the mysql_install_db step.

Download and then install the library using the following commands on the terminal from the folder where you extracted it.

make prefix=$HOME install
cd /usr/local/lib
ln -sv $HOME/libaio.so.1 libaio.so.1
Vijay Kumar Kanta
  • 1,111
  • 1
  • 15
  • 25
  • 1
    Can you provide some more information? E.g., what is the full name of the library and what does it do (or is supposed to do)? Why is it necessary? Where are there some installation instructions and other information? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/14231159/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Oct 28 '21 at 01:44
0

It could be related to an old MySQL process. You need to kill it and restart. Sometimes it can be due to a conflict in a MySQL configuration file. Try to move it and restart MySQL.

Check the following URL for more details.

http://linuxadministrator.pro/blog/?p=225

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • The link is broken: *"Hmm. We’re having trouble finding that site. We can’t connect to the server at linuxadministrator.pro."* – Peter Mortensen Oct 28 '21 at 04:41
0

Disable SELinux in /etc/selinux/config:

SELINUX=disabled and restart the server.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Avinash Singh
  • 1,006
  • 9
  • 10
0

I encountered this issue after swapping server IP addresses. The database was working fine before that. There was an entry in file /etc/my.cnf that I needed to update:

bind-address = xxx.xxx.xxx.xx

It had the old IP address in there.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kamkat86
  • 85
  • 2
  • 4
0

I had the same problem. The reason is quite simple. I installed two MySQL servers. One from MacPorts, and the other from a downloaded package. So I just followed the instruction here and uninstalled the one from the package.

How do you uninstall MySQL from Mac OS X?

After that, MySQL was working well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Benjamin
  • 121
  • 1
  • 4
0

It’s a problem in the 5.5 version:

Here's an example for the [mysqld] section of your my.cnf file:

skip-character-set-client-handshake
collation_server=utf8_unicode_ci
character_set_server=utf8

Reference: 10.3.2 Server Character Set and Collation

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
edwin Yuan
  • 65
  • 1
  • 2
  • 6
0

I tried remove all the *.err files, but I am still getting the same error. I got one of the errors in error log:

[ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace erp/brand uses space ID : 7 at filepath: ./erp/brand.ibd. Cannot open tablespace webdb1/system_user which uses space ID: 7 at filepath: ./webdb1/system_ user.ibd

So I deleted all the ib* files and it worked:

rm -f *.err ib*
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hatted
  • 1,535
  • 1
  • 15
  • 26
  • DONT DELETE Ib* FILES, if you do you will corrupt your InnoDB tables. I just did this and I'cant access my tables now, the real solution that worked to start mysql for me was fix permissions (chown files to user that run mysql) – Arnold Roa May 06 '15 at 18:50
  • 1
    this fix my issue in MacOS Catalina. – Suhendra Dec 19 '20 at 03:47
0

On Mac OS X v10.9 (Mavericks), this script helped me:

bash <(curl -Ls http://git.io/eUx7rg)

And then I reset my password according with ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
izilotti
  • 4,757
  • 1
  • 48
  • 55
0

In my case, the problem was, that the MySQL data directory was moved by accident to the wrong directory (/var/log, and not to /var/lib).

After moving the data back to /var/lib/mysql and restarting server, all everything went back to normal again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
M_per
  • 313
  • 2
  • 12
0

In my Homebrew MySQL installation, I simply had to move the ib_logfile0 and ib_logfile1 located in /usr/local/var/mysql/ to a different directory.

Then I just did mysql.server start and everything worked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gmclelland
  • 187
  • 3
0

I fixed this issue by running

sudo chown -R myUserName /usr/local/var/mysql

Here myUserName is my current login username.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abdul Manan
  • 2,255
  • 3
  • 27
  • 51
0

I have to examine my error file in safe mode to find the root cause:

  1. rm -f /usr/local/var/mysql/*.err
  2. mysqld_safe start
  3. cat mysql/*.err

That revealed an error in the upgrade routine. I tried to fix it, but I couldn't find enough information online. After that I gave up and manually exported the databases:

  1. mysql.server start --upgrade=MINIMAL, so the server will start
  2. mysqldump won't work because it will try to run the full upgrade, but you can use Sequel Pro, phpMyAdmin, etc. to export.
  3. Stop the server, rename the mysql folder to mysql.broken, and do a clean install to get a fresh mysql folder.
  4. Start MySQL, and manually import the .sql files you exported earlier.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ian Dunn
  • 3,541
  • 6
  • 26
  • 44
0

My answer is unprofessional and I do not understand it. I used CentOS and the generic version of MySQL... when I started the mysql with root user my problem solved using --user=root:

/path/to/mysql/support-files/mysql.server start --user=root

If you are using systemctl start mysql.service, you need to change the mysql.service file in /etc/systemd/system/mysql.service:

.
.
.
ExecStart=/path/tp/mysql/support-files/mysql.server start --user=root
ExecStop=/path/to/mysql/support-files/mysql.server stop --user=root
.
.
.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ultra.deep
  • 1,699
  • 1
  • 19
  • 23
0

try with sudo rm -rf /usr/local/var/mysql/HOSTNAME.err (HOSTNAME is my hostname)

0

This is the simplest "PID" error's solution for MySQL Database in macOS:

  1. Run this command:
$ sudo mysql.server start
Starting MySQL
.. SUCCESS! 
  1. Access database with this command:
$ mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.31 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
Database
information_schema
mysql
performance_schema
sys
4 rows in set (0.00 sec)
James Risner
  • 5,451
  • 11
  • 25
  • 47
-1

If you are running a MySQL Galera cluster, such as Percona XtraDB Cluster, check for wsrep_recovery.* files in the data directory (eg: /var/lib/mysql).

I was getting the same message from systemctl when trying to start a node which had been killed by the host's OOM killer, but there wasn't any indication of why the startup failed in any of the normal logs. The wsrep recovery files had the answer, and in my case I needed to start MySQL with the following flag:

mysqld --tc-heuristic-recover=ROLLBACK
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Robert Hunt
  • 7,914
  • 5
  • 40
  • 43
-3
open /usr/local/var/mysql

You just remove the folder in Finder, and

brew install mysql

install again.

I've solved from this solution.

But this solution will delete your database.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Seungwon
  • 276
  • 3
  • 10
  • But that would also delete all of your local databases. Not really a perfect solution. – merauluka Apr 15 '16 at 04:23
  • oh I've missed that. Thank you for adding the comment – Seungwon Apr 21 '16 at 03:49
  • On macOS presumably. Can you add information about versions [to your answer](https://stackoverflow.com/posts/35737322/edit), etc. (e.g., [Mac OS X v10.11](https://en.wikipedia.org/wiki/OS_X_El_Capitan) (El Capitan))? (But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Oct 30 '21 at 03:20