我尝试在 ubuntu 16.04 上使用 mysql。当我执行时mysql -u root -p
,出现此错误:'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
在 error.log 文件中,我看到此错误警报:
2020-10-24T15:43:52.556275Z 0 [ERROR] Failed to create a socket for IPv4 '127.0.0.1':
errno: 13.
2020-10-24T15:43:52.556289Z 0 [ERROR] Can't create IP socket: Permission denied
2020-10-24T15:43:52.556299Z 0 [ERROR] Aborting
我尝试卸载并重新安装 mysql,但没有任何结果。我该如何解决这个问题?
编辑:通过sudo systemctl status mysql.service
,我得到了这个:
● mysql.service - MySQL Community Server
Loaded: loaded (/etc/systemd/system/mysql.service; disabled; vendor
preset: disabled)
Active: failed (Result: exit-code) since Sun 2020-10-25 15:05:42 CET;
4min 5s ago
Process: 18804 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
(code=exited, status=203/EXEC)
Oct 25 15:05:42 thales systemd[1]: mysql.service: Scheduled restart
job, restart counter is at 5.
Oct 25 15:05:42 thales systemd[1]: Stopped MySQL Community Server.
Oct 25 15:05:42 thales systemd[1]: mysql.service: Start request
repeated too quickly.
Oct 25 15:05:42 thales systemd[1]: mysql.service: Failed with result
'exit-code'.
Oct 25 15:05:42 thales systemd[1]: Failed to start MySQL Community
Server.
这是里面的完整日志/var/log/mysql/error.log
2020-10-25T12:46:01.869691Z 0 [System] [MY-013169] [Server]
/usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as
process 16663
2020-10-25T12:46:01.869808Z 0 [ERROR] [MY-010338] [Server] Can't find
error-message file '/usr/share/mysql-8.0/errmsg.sys'. Check error-
message file location and 'lc-messages-dir' configuration directive.
2020-10-25T12:46:01.880669Z 1 [System] [MY-013576] [InnoDB] InnoDB
initialization has started.
2020-10-25T12:46:04.317333Z 1 [System] [MY-013577] [InnoDB] InnoDB
initialization has ended.
2020-10-25T12:46:09.821004Z 6 [Warning] [MY-010453] [Server]
root@localhost is created with an empty password ! Please consider
switching off the --initialize-insecure option.
2020-10-25T12:46:22.034576Z 0 [System] [MY-010116] [Server]
/usr/sbin/mysqld (mysqld 8.0.21) starting as process 16714
2020-10-25T12:46:22.034766Z 0 [ERROR] [MY-010338] [Server] Can't find
error-message file '/usr/share/mysql-8.0/errmsg.sys'. Check error-
message file location and 'lc-messages-dir' configuration directive.
2020-10-25T12:46:22.061157Z 1 [System] [MY-013576] [InnoDB] InnoDB
initialization has started.
2020-10-25T12:46:23.091350Z 1 [System] [MY-013577] [InnoDB] InnoDB
initialization has ended.
2020-10-25T12:46:23.368045Z 0 [ERROR] [MY-011292] [Server] Plugin
mysqlx reported: 'Preparation of I/O interfaces failed, X Protocol
won't be accessible'
2020-10-25T12:46:23.368243Z 0 [ERROR] [MY-011300] [Server] Plugin
mysqlx reported: 'Setup of bind-address: '*' port: 33060 failed,
`socket()` failed with error: Permission denied(13)'
2020-10-25T12:46:23.368395Z 0 [ERROR] [MY-013597] [Server] Plugin
mysqlx reported: 'Value '*' set to `Mysqlx_bind_address`, X Plugin
can't bind to it. Skipping this value.'
2020-10-25T12:46:23.368552Z 0 [ERROR] [MY-011300] [Server] Plugin
mysqlx reported: 'Setup of socket: '/var/run/mysqld/mysqlx.sock'
failed, can't create lock file /var/run/mysqld/mysqlx.sock.lock'
2020-10-25T12:46:23.727103Z 0 [Warning] [MY-010068] [Server] CA
certificate ca.pem is self signed.
2020-10-25T12:46:23.727337Z 0 [System] [MY-013602] [Server] Channel
mysql_main configured to support TLS. Encrypted connections are now
supported for this channel.
2020-10-25T12:46:23.728781Z 0 [ERROR] [MY-010250] [Server] Failed to
create a socket for IPv4 '0.0.0.0': errno: 13.
2020-10-25T12:46:23.729006Z 0 [ERROR] [MY-010255] [Server] Can't
create IP socket: Permission denied
2020-10-25T12:46:23.729451Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-10-25T12:46:25.486906Z 0 [System] [MY-010910] [Server]
/usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21) MySQL Community
Server - GPL.