通过套接字连接到本地的MySQL服务器

9

错误 2002 (HY000):无法通过套接字 '/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器

我尝试了网上找到的所有方法,但无法解决 Ubuntu 11.04 上的问题。

我尝试了以下几个步骤:

  • 使用 sudo /usr/sbin/mysqld start 手动启动 mysqld
  • 使用 service mysqld start 启动 mysqld
  • 使用 ps ax | grep mysqld 检查它是否正在运行,并得到结果 3419 pts/0 S+ 0:00 grep --color=auto mysqld
  • 手动在 /var/run/mysqld/mysqld.sock 创建文件
  • 授予 mysql 用户权限
  • 尝试卸载并重新安装,但仍然无法解决问题
  • 尝试使用 tasksel 配置 LAMP,其他所有内容都正常工作,但 mysql 仍然生成相同的错误

当使用 mysqld -P 3305 运行时会生成错误。

110630  0:24:24 [Warning] Can't create test file /var/lib/mysql/nazar-studio.lower-test
110630  0:24:24 [Warning] Can't create test file /var/lib/mysql/nazar-studio.lower-test
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13)
110630  0:24:24 [ERROR] Aborting

110630  0:24:24 [Note] mysqld: Shutdown complete

这里是MySQL错误日志。
10630  0:07:22 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:22  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:22  InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
110630  0:07:22  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
110630  0:07:22  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...
110630  0:07:22  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: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
110630  0:07:23  InnoDB: Started; log sequence number 0 0
110630  0:07:23  InnoDB: Starting shutdown...
110630  0:07:28  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:28 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:28  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:28  InnoDB: Completed initialization of buffer pool
110630  0:07:28  InnoDB: Started; log sequence number 0 44233
ERROR: 1064  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE user ADD column Show_view_priv enum('N','Y') CHARACTER SET utf8 NOT ' at line 1
110630  0:07:28 [ERROR] Aborting

110630  0:07:28  InnoDB: Starting shutdown...
110630  0:07:34  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:34 [Note] /usr/sbin/mysqld: Shutdown complete

110630  0:07:34 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:34  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:34  InnoDB: Completed initialization of buffer pool
110630  0:07:34  InnoDB: Started; log sequence number 0 44233
110630  0:07:34  InnoDB: Starting shutdown...
110630  0:07:39  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:39 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:39  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:39  InnoDB: Completed initialization of buffer pool
110630  0:07:39  InnoDB: Started; log sequence number 0 44233
ERROR: 1050  Table 'plugin' already exists
110630  0:07:39 [ERROR] Aborting

110630  0:07:39  InnoDB: Starting shutdown...
110630  0:07:44  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:44 [Note] /usr/sbin/mysqld: Shutdown complete

110630  0:18:30 [Note] Plugin 'FEDERATED' is disabled.
110630  0:18:30  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:18:30  InnoDB: Completed initialization of buffer pool
110630  0:18:30  InnoDB: Started; log sequence number 0 44233
mysqld: Too many arguments (first extra is 'start').
Use --verbose --help to get a list of available options
110630  0:18:30 [ERROR] Aborting

110630  0:18:30  InnoDB: Starting shutdown...
110630  0:18:35  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:18:35 [Note] mysqld: Shutdown complete

如何解决这个错误?


1
建议编辑您的问题,包括您已尝试的步骤,以免我们为您重复这些失败的尝试! - p.campbell
1
非常好的问题,细节描述得很好,而且您实际上已经尝试自己解决它了。 - Lightness Races in Orbit
你是如何尝试连接它的呢? - Lightness Races in Orbit
mysql -uroot -p,它报错了,如果我使用命令 sudo service stop mysql,就可以正确执行。但是如果我使用命令 sudo service start mysql,它需要大约20秒钟的时间。 - Nazar Hussain
6个回答

16

我进行了实验,最终通过这些命令解决了问题

sudo chown mysql:root /var/lib/mysql/ -R
sudo chmod g+rw /var/lib/mysql/ -R
sudo /usr/sbin/mysqld --skip-grant &

它开始运行了……好开心啊!!!!!!!


那时它还能正常工作。但是在重新启动后,同样的错误再次出现,而且这次它无法工作了。 - Nazar Hussain
每次我重新启动时都需要输入这些命令才能运行。 - Nazar Hussain

4

您的日志实际上告诉您问题所在:

mysqld: 参数太多(第一个额外的是“start”)。

只需不使用单词“start”启动守护程序即可。而不是:

sudo /usr/sbin/mysqld start

应该只有:

sudo /usr/sbin/mysqld


1

看起来无法在 /var/lib/mysql/ 中创建文件。如果您查看错误代码 13,通常意味着权限错误。

1)确保 mySQL 可以写入目录 /var/lib/mysql 和/或者 mySQL 拥有该目录。执行以下操作:

cd /var/lib ; ls -la | grep mysql

确保无误。

2) 如果您正在尝试使用mySQL用户启动它,请改用root启动(您可能正在使用root,但这也值得检查)。

3) 如果您运行类似于SElinux的东西,请确保您为mySQL访问启用了它。我怀疑这种情况不会发生,但还是值得检查。

4) 小提示:不要创建sock文件 - mysql会在其正常运行后自己创建一个。如果它仍然在运行目录中,请将其删除。


另外,有人能把这个问题转到Serverfault吗?这个问题更适合那个论坛。 - Rilindo
它给出了以下输出“drwx------ 3 mysql mysql 4096 2011-06-30 00:18 mysql”,这意味着它是由mysql用户拥有并具有读/写访问权限。我正在使用“mysql -uroot -p”用mysql的root用户启动mysql。然后我删除了该文件。 - Nazar Hussain

1
如果您安装了多个MySQL服务器,请确保运行正确的MYSQL或更改路径设置。例如:
/opt/lampp/bin/mysql -u root -p 

我已经安装了XAMPP,这个解决方案对我有用。


0
尝试关闭套接字(这可能取决于您的操作系统)
rm /var/lib/mysql/mysql.sock rm:删除套接字“/var/lib/mysql/mysql.sock”?y 重新启动服务
service mysqld start

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接