无法通过套接字'/var/mysql/mysql.sock'连接到本地 MySQL 服务器

无法通过套接字'/var/mysql/mysql.sock'连接到本地 MySQL 服务器

最近,当我尝试登录 mysql 时出现此错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

我读到另一条威胁说这可能是由于系统过时造成的,所以我运行了所有系统更新,但没有效果。所以我转向重新启动 mysql 可能会有效,所以我尝试了这个,但遇到了权限问题:

service mysqld restart
Stopping mysqld:                                           [  OK  ]
touch: cannot touch ‘/var/log/mysqld.log’: Permission denied
chown: changing ownership of ‘/var/log/mysqld.log’: Operation not permitted
chmod: changing permissions of ‘/var/log/mysqld.log’: Operation not permitted
chown: changing ownership of ‘/var/lib/mysql’: Operation not permitted
chmod: changing permissions of ‘/var/lib/mysql’: Operation not permitted
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]

我将 mysqld.log 的权限更改为 644,但仍然出现相同的错误。查看日志文件后,我也不明白是什么原因导致了这个问题。以下是 mysqld.log 文件的内容:

130427 21:48:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130427 21:48:58 [Note] Plugin 'FEDERATED' is disabled.
130427 21:48:58 InnoDB: The InnoDB memory heap is disabled
130427 21:48:58 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130427 21:48:58 InnoDB: Compressed tables use zlib 1.2.5
130427 21:48:58 InnoDB: Using Linux native AIO
130427 21:48:59 InnoDB: Initializing buffer pool, size = 128.0M
130427 21:48:59 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
130427 21:48:59  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
130427 21:48:59  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
130427 21:48:59  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
130427 21:49:00  InnoDB: Waiting for the background threads to start
130427 21:49:01 InnoDB: 5.5.31 started; log sequence number 0
130427 21:49:01 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130427 21:49:01 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
130427 21:49:01 [Note] Server socket created on IP: '0.0.0.0'.
130427 21:49:01 [Note] Event Scheduler: Loaded 0 events
130427 21:49:01 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

如果有人能给我指明正确的方向,我将不胜感激!谢谢。

答案1

根据您提供的信息,这似乎是 MySQL 实例运行时的用户权限问题。尝试运行以下命令并检查它是否能解决您的问题:

chown -R mysql:mysql /var/lib/mysql

还可以通过执行以下命令检查 MySQL 实例是否正在您的机器上运行:

ps ax | grep mysql

如果它没有运行,请尝试使用以下命令以 root 权限启动它并检查

sudo service mysql start

相关内容