在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

当前回答

请按照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

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

其他回答

请按照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

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

这是5.5版本的一个问题:

下面是my.cnf文件[mysqld]部分的示例:

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

参考:10.3.2服务器字符集和排序规则

不知何故,我搞砸了我在Mac OS X v10.11 (El Capitan)上的权限,决定从头开始重新安装MySQL。

我在El Capitan上使用Homebrew,并决定重新安装:

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

新安装的文件权限从_mysql更改为包含我的用户名:

ls -alh /usr/local/var/mysql
drwxr-xr-x   22 lfender  admin   748B Mar 22 09:58 .
# ... etc.

我希望这对你有用。

在检查错误日志后,我发现了这个:

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

为了解决这个问题,我给了整个mysql文件夹的所有权:

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

然后(你也可以做命令行),我应用权限(一旦我把所有权给_mysql和mysql用户),从文件夹/usr/local/mysql-5.5.21-osx10.6-x86_64的“获取信息”菜单中的所有附带的文件夹。你不需要把它传给别名,因为它只是一个别名。

文件夹的名称取决于MySQL的安装版本。

当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