MySql server startup error 'The server quit wi

2019-01-01 10:18发布

问题:

On Snow Leopard, starting MySQL gives the following error:

The server quit without updating PID 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

回答1:

try to find your log file with suffix \".err\", there should be more info. It might be in:

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

It\'s probably 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 username on output of 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 mysql or your_user

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



回答2:

Did you follow the instructions from brew install mysql?

Set up databases to run AS YOUR USER ACCOUNT with:

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:

  • http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
  • http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html

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



回答3:

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.



回答4:

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

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


回答5:

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


回答6:

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.



回答7:

This error can occur when trying to start msql after it was improperly shutdown.

  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 this command: lsof -i: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)
  1. Terminate the process running mysql: kill -15 4249

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

  1. Now mysql should startup with no problems: mysql.server start


回答8:

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.



回答9:

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



回答10:

The solution that worked for me was here: https://serverfault.com/questions/334284/cant-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 OS X 10.8.2 and mysql was installed with homebrew.

chmod 0755 /var
chown root:wheel /var/tmp
sudo chmod 0771 /usr/local/var/mysql/*


回答11:

For me the fix was simple:

top

showed that mysqld was already running

sudo killall mysqld 

then allowed the process to start



回答12:

I\'m using,

  • brand-new MacBook Pro OSX 10.7.3.x
  • gcc via OSX GCC Installer

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

When I tried to start it up,

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

I ran this command,

west$ /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 with top level of the mysql directory (IE, usr/local/Cellar/mysql/5.5.25). Running it directly within the /scripts directory does not give it enough context for it to run.



回答13:

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.



回答14:

Try to remove 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.



回答15:

I had this problem while trying to brew upgrade on MacOS X 10.7.5.

Unfortunately mysql was also upgraded to 5.6.10 from 5.5.14. Tried the new, 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


回答16:

Start Mysql in safe mode

/usr/local/mysql/bin/mysqld_safe start

OR

on 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


回答17:

It seems that 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.



回答18:

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


回答19:

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

Well, I assume the OP has fixed it at this point... but hopefully this points the others seeing this error in the right direction.



回答20:

I hope this work 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.



回答21:

Had the same issue, for me it was doing a brew remove while having a previous install of the mysqld running. Seems 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.



回答22:

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


回答23:

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.

Than 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

On 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, than you need to change permission

chown -R _mysql /var/log/mysql

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

Hope this can help others here... The key is to read the error and log and find whats is wrong...



回答24:

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



回答25:

Simple....

Fix the 2002 MySQL Socket error

Fix the looming 2002 socket error – which is linking where MySQL places the socket and where OSX thinks it should be, MySQL puts it in /tmp and OSX 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 Help me A LOT! i took this guide from the guys on http://coolestguidesontheplanet.com/



回答26:

The problem is a permissions one, it can\'t start because it can\'t write to mac.err because its 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 its all good. However, if you start it as root, it will create a mac.err (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 owned by someone else.
  3. Start is as the right user.


回答27:

In my case, I got this issue on vps, cPanel.

I was try most of the above answers, but not success.

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

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

  1. Open that file (/var/lib/mysql/111318.vps-11.com.err) and chek the bottom for lates 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

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

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

https://forums.cpanel.net/threads/mysql-is-not-running.407142/

  1. (Re)Start your mysql


回答28:

For me I had to reinstall mysql

brew reinstall mysql

and then below To have launchd start mysql now and restart at login:

brew services start mysql


回答29:

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



回答30:

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



标签: mysql