问题描述:
打开mysql workbench,显示无法连接。
在终端启动,也报错。
sudo /usr/local/mysql/support-files/mysql.server start
报错内容:
Starting MySQL
.Logging to '/opt/mysql/data/MacBook-Air.local.err'.
ERROR! The server quit without updating PID file (/opt/mysql/data/MacBook-Air.local.pid).
使用chmod命令给mysql文件夹赋予权限
sudo chmod 777 /usr/local/mysql/
重新启动mysql。
若还是同样的错误,则可查看错误日志/usr/local/mysql/data/mysqld.local.err
。找到最新的日志,根据报错内容解决问题。
例:此次报错为
2021-03-29T08:26:36.420671Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.21) starting as process 83688
2021-03-29T08:26:36.428356Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-03-29T08:26:36.429554Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2021-03-29T08:26:36.444654Z 0 [ERROR] [MY-011370] [Server] Plugin keyring_file reported: 'File '/usr/local/mysql/keyring/keyring' not found (OS errno 13 - Permission denied)'
2021-03-29T08:26:36.445867Z 0 [ERROR] [MY-011355] [Server] Plugin keyring_file reported: 'keyring_file initialization failure. Please check if the keyring_file_data points to readable keyring file or keyring file can be created in the specified location. The keyring_file will stay unusable until correct path to the keyring file gets provided'
2021-03-29T08:26:36.445996Z 0 [ERROR] [MY-010202] [Server] Plugin 'keyring_file' init function returned error.
2021-03-29T08:26:36.454101Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-03-29T08:26:36.826360Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-03-29T08:26:36.974873Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2021-03-29T08:26:36.992670Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2021-03-29T08:26:37.008506Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
2021-03-29T08:26:37.033705Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-03-29T08:26:37.034309Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-03-29T08:26:37.041856Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/usr/local/mysql/data' in the path is accessible to all OS users. Consider choosing a different directory.
2021-03-29T08:26:37.102256Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.21' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server - GPL.
其中为【ERROR】信息为
- Plugin keyring_file reported: ‘File ‘/usr/local/mysql/keyring/keyring’ not found (OS errno 13 - Permission denied)’
- Plugin keyring_file reported: ‘keyring_file initialization failure. Please check if the keyring_file_data points to readable keyring file or keyring file can be created in the specified location. The keyring_file will stay unusable until correct path to the keyring file gets provided’
- Plugin ‘keyring_file’ init function returned error.
检查是否存在keyring
这个文件,若不存在就创建,若已存在则对它赋予权限
sudo chmod 777 /usr/local/mysql-8.0.21-macos10.15-x86_64/keyring/keyring
我在这一步已解决。
若还报错,还可以使用ps
命令检查是否已经存在mysql进程
ps -ef | grep mysqld
若有,则使用kill -9 进程号
来杀死这个进程即可。
另外,也可查看记载mysqld进程pid的文件/usr/local/mysql/data/mysqld.local.pid
。