在通过 Brew 安装 MySQL 之后,我得到了一个错误——服务器退出而没有更新 PID 文件

好的,我已经搜索了所有地方,花了相当多的时间安装,卸载,尝试各种选项,但没有成功。

我在 Mac OS X Lion (10.7.3)上,正在尝试安装 Python MySQL。

我通过 HomeBrew 成功地安装了 Python 和 MySQL。 巨蟒很管用。

安装 MySQL 之后,我遵循了前两个步骤-unset 和 mysql_install_db命令。

现在,当我尝试启动 mysql“ mysql.server start”时,会得到以下错误

ERROR! The server quit without updating PID file (/usr/local/var/mysql/Brajeshwar.local.pid).
  • Brajeshwar是我机器上的用户名。
218580 次浏览

If I remember correctly it is a permissions issue. Try to 'touch' and 'chmod' the pid file or the folder the file is held in.

EDIT 2012/09/18: As pointed out by Kane, make sure the mysql database is properly set up before doing anything else. See “PID error on mysql.server start?” for more info.

Original answer kept for history's sake: It most likely is a permissions issue. Check /usr/local/var/mysql/*.err. Mine said:

120314 16:30:14  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 ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
120314 16:30:14 mysqld_safe mysqld from pid file /usr/local/var/mysql/janmoesen.local.pid ended

I also had to do this:

sudo chown _mysql /usr/local/var/mysql/*

First mv -f /var/lib/mysql /var/lib/mysql.bak and try the command mysql_install_db --user=mysql --ldata=[destination] replace the destination with the data directory, after that start the MySQL with /etc/init.d/mysql restart

For me it worked with:

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

I found that it was a permissions issue with the mysql folder.

chmod -R 777 /usr/local/var/mysql/

solved it for me.

November, 2014: If you're getting this error on MySQL 5.6.x on Mac OS X Mavericks or Yosemite and want to use MySQL with PHP locally (/tmp/mysql.sock is where PHP PDO expects to find the sock file), here is what fixed it for me:

1) Uncomment the default homebrew config file lines and edit as below

$ sudo vi /usr/local/Cellar/mysql/5.6.21/my.cnf
...
basedir = /usr/local/Cellar/mysql/5.6.21
datadir = /usr/local/var/mysql
port = 3306
server_id = <UNIQUE_NUMBER_HERE_OR_LEAVE_COMMENTED_OUT>
socket = /tmp/mysql.sock
pid-file = /usr/local/var/mysql/[BOXNAME].local.pid
....

BOXNAME is what you have in your System Prefs -> Network as the unique id for your computer on the network.

2) Set permissions on all the files in the mysql datadir. These were all owned by [my_username]. MySQL is very picky about this and refuses to create the pid file unless it (the user _mysql) owns the directory.

$ sudo chown -R _mysql:mysql /usr/local/var/mysql

3) Start MySQL using the bash helper/wrapper script:

$ sudo mysql.server start
Starting MySQL
. SUCCESS!

Hope that helps. If the above doesn't work for you, try to run the mysqld_safe binary manually in the Cellar/mysql/VERSION_/bin/ directory and check what the settings are (if it runs)

sudo /usr/local/Cellar/mysql/5.6.12/bin/mysqld_safe &

If that runs, you can

ps aux | grep mysql

and see something like

[username]  6881   0.0  2.7  3081392 454836   ??  S     8:52AM   0:00.54 /usr/local/Cellar/mysql/5.6.21/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.21 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.21/lib/plugin --verbose --log-error=/usr/local/var/mysql/BOXNAME.local.err --pid-file=/usr/local/var/mysql/BOXNAME.local.pid

I'm not sure why that worked for me but it shows you where I got the my.cnf config file options from. You can also use the command line options to try to troubleshoot when starting mysqld manually.

If you do run manage to run MySQL server using mysqld_safe, you may have to do this to shut it down before trying the mysql.server bash helper. Resist the urge to kill -9 [PID] because you can corrupt your data.

mysqladmin -uroot shutdown

Good luck!

While Installing from source,please follow the instruction in file INSTALL-SOURCE

where installation instruction are given in section 2.8

after installation ,check are there any process running of mysql with ps aux | grep mysql

You'll find like this

root      1817  0.0  0.0 108336  1228 ?        S    Jan21   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mail.gaurav.local.pid
mysql     2141  0.0  1.2 497660 24588 ?        Sl   Jan21   0:26 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mail.gaurav.local.err --pid-file=/usr/local/mysql/data/mail.gaurav.local.pid --socket=/tmp/mysql.sock --port=3306
root      5659  0.0  0.0 103256   840 pts/13   S+   11:30   0:00 grep mysql

kill all process related to mysql,and then try to start mysql server

My issue was that I started server as sudo once and then tried to restart as a local user.

Here mysql was not able to write to '.err' file owned by root. I had to remove that file and restart the server:

sudo rm /usr/local/var/mysql/*.err
mysql.server start

I’ve got a similar problem with MySQL on a Mac (Mac Os X Could not startup MySQL Server. Reason: 255 and also “ERROR! The server quit without updating PID file”). After a long trial and error process, finally in order to restore the file permissions, I’ve just do that:

launch the Disk Utilities.app
choose my drive on the left panel
click on the “Repair disk permissions” button

This did the trick for me. Hoping this can help someone else.

This is file permission problem. Check disk permissions and repair.

Osx => Cmd+Space => Disk Utilty => Verify Disk Permissions.

Verify completed after Repair Disk Permissions. mysql.server start command is worked succesfuly.

sudo chmod -R 777 /usr/local/var/mysql/

works for me.

This worked for me:

sudo chmod -R 777 /usr/local/var/mysql/
sudo /usr/local/mysql/support-files/mysql.server start

I had this issue on mac 10.10.5 Yosemite

What I did to solve this

cd /usr/local/var/mysql
sudo rm *.err && sudo rm *.pid
sudo reboot
sudo mysql.server start

I had the same issue:

But the situation was, every time i try to enter:

/usr/local/mysql/support-files/mysql.server start

a file named localhost.pid is created instead of iMax0.local.pid which was stated in the error:

ERROR! The server quit without updating PID file (/usr/local/mysql/data/iMax0.local.pid).

Solution that works for me was copying localhost.pid and renaming it to iMax0.local.pid.

I had the similar issue. But the following commands saved me.

cd /usr/local/Cellar
sudo chown _mysql mysql

My solution on OSX El Capitan was:

sudo chmod ugo+w /tmp

It was broken suddenly.

The error was:

ERROR! The server quit without updating PID file

and the log showed:

Can't start server : Bind on unix socket: Permission denied

It might also be helpful to note, that under OSX there is no my.cnf file by default and not needed by default, which I did not know. Good luck!

I had the same issue on OS X El Capitan, here's the terminal command sequence that fixed it for me.

Delete error files (you'll have to change the path depending on your setup)

sudo rm /usr/local/mysql/data/*.err

Find the info for the mysql process that's still running and kill it:

ps -A | grep -m1 mysql | awk '{print $1}' | sudo xargs kill -9

Now restart MySQL:

/usr/local/mysql/support-files/mysql.server start

I ended up with completely reinstalling of mysql, and it finally worked out.

WARNING This will remove all of your databases, so make sure to save dumps first.

brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql


brew install mysql
mysqld --initialize --explicit_defaults_for_timestamp
mysql.server start # no sudo!
$ sudo mysql.server restart

It works for me.

What worked for me was:

  1. Go to your mysql installation directory
  2. sudo chmod -R 777 data
  3. Then go back one directory
  4. cd support-files/
  5. sudo ./mysql.server start

After that the server started running.

But the problem with this method is that I have to repeat this every time I want to start the mysql now. Don't know why it started behaving like this suddenly.

None of the answers worked for me. However, I simply did sudo mysql.server start and it worked nicely.

Also, for me, it did NOT show permissions issue in *.err file.

This worked for me on 10.12.2 :

$ rm /usr/local/var/mysql/*.err

then

$ brew services restart mysql

Find usr/local/var/mysql/your_computer_name.local.err file and understand the more information about error

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

It's probably problem with permissions

  1. Find if mysql is running and kill it

ps -ef | grep mysql

kill -9 PID

where PID is second column value 2. check ownership of mysql

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

if it is owned by root, change it mysql or your user name



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

I had this problem on Linux, but the cause is relevant to any mysql installation. In my case, the server was crashing before startup was complete and the pid file updated. The error messages were seen when starting up mysqld directly instead of via "service mysql start".

In my case, the cause was the partition where the log files were located being full. Removing log files permitted mysql to start again. To test for this issue, go to the location of your mysql activity logs, and do df ..

Try this (OSX)

Step 1: ps -aux | grep mysql

Then kill the 4 digits PID number

Step 2: kill 1965

Step 3: mysql.server start

Or having hard time to locate those PID numbers, try this below

Step 1 again: ps -aux | grep mysql

Step 2 again: killall

Step 3 again: mysql.server start

If you have upgraded your mysql installation to 8.x, check if your previous version is supported for upgradation.

If not, mysql will not work! Uninstall your mysql along with all configuration files in /usr/local/var/mysql (remove the whole folder). Reinstall mysql.

NOTE: reinstalling might lead to loss of data.

all solutions above doesn't work for me. but they give me some clues to fix this error.

mysql.server start ----error The server quit without updating PID file

I installed mysql@5.7 on my macbook mojave with homebrew

brew install mysql@5.7

mysql error log located in /usr/local/var/mysql/IU.lan.err,there is one line in it: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

after trying many posts in goole search engine,I turned to baidu https://blog.csdn.net/xhool/article/details/52398042 inspired by this post,I found the solution:

rm /usr/local/var/mysql/*

mysqld --initialize

a random password for root user will be shown in bash. but the command mysql -uroot -p[theRandomPassword] cant work.so I have to reset password. create a init file with contents like this

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

place it in any directory easy to find,such as Desktop

mysqld --init-file=[YourInitFile] &

many logs printed on your screen.

mysql -uroot -pMyNewPass

enjoy your high-version mysql!

Please check the log , you will get more detailed information .

Use the below command to tail the error log

tail -100 /usr/local/var/mysql/<user_name>.local.err

For me , one of the directory is missing , once created the server has started .

Happened to me because I was actually switching from MariaDB to Mysql. Switching back to MariaDB solved this.

I'm guessing the existing database wasn't compatible.

Solved this using sudo chown -R _mysql:_mysql /usr/local/var/mysql Thanks to Matteo Alessani

The key takeaway is to check the .err file, by default on Mac OSX it's in /usr/local/var/mysql.

That log filed revealed to me that I had to delete the following files:

ibdata1
ib_logfile0
ib_logfile1

Running MySQL with mysql.start worked successfully after that. Note that deleting those files will likely causes data loss.

This error may be actually being show because mysql is already started. Try to see the current status by:

mysql.server status