在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

当前回答

我的回答很不专业,我不理解。我用的是CentOS和通用版的MySQL…当我用root用户启动mysql时,我的问题用——user=root解决了:

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

如果你正在使用systemctl启动mysql。服务,您需要更改mysql。/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
.
.
.

其他回答

我也有同样的问题。原因很简单。我安装了两个MySQL服务器。一个来自MacPorts,另一个来自下载的包。所以我只是按照这里的说明,从包中卸载了一个。

如何从Mac OS X上卸载MySQL ?

在那之后,MySQL运行得很好。

它可能与旧的MySQL进程有关。你得关掉它,重新启动。有时可能是由于MySQL配置文件中的冲突。尝试移动它并重新启动MySQL。

查看下面的URL了解更多详细信息。

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

当MySQL被不正确地关闭后试图启动MySQL时,可能会发生此错误。

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. 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) 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. Now MySQL should start up with no problems: mysql.server start

这是macOS中MySQL数据库最简单的“PID”错误解决方案:

执行如下命令:

$ sudo mysql.server start
Starting MySQL
.. SUCCESS! 

使用此命令访问数据库:

$ 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)

对我来说,解决方案是覆盖/纠正/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

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