在Mac OS X v10.6 (Snow Leopard)上,启动MySQL会出现以下错误:

服务器退出,没有更新PID文件

文件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

当前回答

我通过跑步解决了这个问题

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

这里myUserName是我当前的登录用户名。

其他回答

对我有效的解决方案是:不能在MySQL服务器上创建PID文件,权限被拒绝

改变我的一些权限似乎奏效了。我使用的是一台2012年年中的MacBook Air,安装了Mac OS X v10.8.2 (Mountain Lion), MySQL安装了Homebrew。

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

我在交换服务器IP地址后遇到了这个问题。在此之前,数据库工作正常。在/etc/my.cnf文件中有一个条目需要更新:

bind-address = xxx.xxx.xxx.xx

里面有旧的IP地址。

请按照brew install mysql的说明安装mysql。

设置数据库以您的用户帐户运行:

对于MySQL 5.x:

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

要在另一个文件夹中设置基表,或者使用不同的用户运行mysqld,请查看mysqld_install_db的帮助:

mysql_install_db --help

查看MySQL文档:

4.4.3 mysql_install_db -初始化MySQL数据目录 2.10.4 MySQL初始帐户安全

对于MySQL 8.x:

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

确保上面的数据目录/usr/local/var/mysql为空。必要时备份。

例如,要以“mysql”用户运行,你可能需要sudo:

sudo mysql_install_db ...options...

手动启动mysqld:

mysql.server start

注意:如果失败,您可能忘记运行上面的前两个步骤

在我的情况下,我得到了这个问题在一个VPS和cPanel。

我试了之前的大部分答案,但都没有成功。

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). 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 How solve this: Recovering and fixing the table indexes by command: [~]# myisamchk -r /var/lib/mysql/mysql/db.MYI MySQL is not running (Re)Start your MySQL server

对我来说,解决方案是覆盖/纠正/etc/my/cnf中的数据目录

我用自述文件中提供的说明从源代码构建MySQL 5.5.27:


# 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在没有解释的情况下自行终止。运行/etc/init.d/mysql.服务器启动导致错误:

服务器退出没有更新PID文件

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!

所以我只是编辑了/etc/my.cnf,在部分[mysqld]下,我添加了一个指令,显式地将mysql的数据目录指向var(因为我通常期望它是任何方式),这样做之后,mysqld启动得很好。add指令看起来像这样:

数据= /usr/地方/mysql/var

为我工作。希望对你有所帮助。