Docker无法通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器(2)Ubuntu

时间:2017-04-03 21:42:06

标签: mysql linux sockets ubuntu docker

我正在使用docker并将我的本地mysql挂载到docker容器并连接MySql-Workbench所以我可以在这里查看数据库(试验)是我运行的命令。

docker run -d --name alldb-mysql -v /var/lib/mysql:/var/lib/mysql -e MYSQL_USER=root -e MYSQL_PASSWORD=password -p 3306:3306 mysql:latest

我停止我的容器并将其删除后,我无法启动/重启mysql(本地安装)。当我运行sudo /etc/init.d/mysql start时,它会返回

[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!

所以我检查了systemctl status mysql.service

     mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Mon 2017-04-03 22:26:15 IST; 26s ago
  Process: 5470 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 5465 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 5470 (code=exited, status=1/FAILURE);         : 5471 (mysql-systemd-s)
    Tasks: 2
   Memory: 1.6M
      CPU: 222ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─5471 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─6579 sleep 1

Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.980564Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explici
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.980614Z 0 [Warning] Can't create test file /var/lib/mysql/n.lower-test
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.980638Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.17-0ubuntu0.16.04.1) starting as process 5470 .
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.981928Z 0 [Warning] Can't create test file /var/lib/mysql/n.lower-test
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.981936Z 0 [Warning] Can't create test file /var/lib/mysql/n.lower-test
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982122Z 0 [ERROR] failed to set datadir to /var/lib/mysql/
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982142Z 0 [ERROR] Aborting
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982162Z 0 [Note] Binlog end
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982213Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Apr 03 22:26:15 n systemd[1]: 

我还尝试使用我的详细信息登录mysql: 返回的mysql -uroot -ppassword1

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

当我在var lib目录上运行以下命令ls -la /var/lib/ | grep mysql时,它返回。

drwx------ 12 root          docker        4096 Apr  3 21:17 mysql
drwx------  2 mysql         mysql         4096 Feb 23 22:35 mysql-files
drwx------  2 mysql         mysql         4096 Feb 23 22:35 mysql-keyring
drwxr-xr-x  2 root          root          4096 Jan 18 21:45 mysql-upgrade

通过我看到的东西(很好的码头工作者)搞砸了我在mysql目录上的所有权。

如果我运行ls -la /var/lib/mysql,则返回

ls: cannot open directory '/var/lib/mysql': Permission denied

并使用sudo sudo ls -la /var/lib/mysql 运行相同的命令,它返回

total 188480
drwx------ 12 root         docker     4096 Apr  3 21:17 .
drwxr-xr-x 80 root         root       4096 Mar 29 19:28 ..
-rw-r-----  1 guest-okauxv docker       56 Feb 23 22:35 auto.cnf
drwxr-x---  2 guest-okauxv docker     4096 Mar 24 23:51 concretepage
-rw-r--r--  1 guest-okauxv docker        0 Feb 23 22:35 debian-5.7.flag
drwxr-x---  2 guest-okauxv docker     4096 Mar 25 00:10 myfidser
drwxr-x---  2 guest-okauxv docker     4096 Mar  4 00:54 myotherFliDB
drwxr-x---  2 guest-okauxv docker     4096 Mar  1 12:33 testFFAPI
-rw-r-----  1 guest-okauxv docker      679 Apr  3 21:16 ib_buffer_pool
-rw-r-----  1 guest-okauxv docker 79691776 Apr  3 21:17 ibdata1
-rw-r-----  1 guest-okauxv docker 50331648 Apr  3 21:17 ib_logfile0
-rw-r-----  1 guest-okauxv docker 50331648 Feb 23 22:35 ib_logfile1
-rw-r-----  1 guest-okauxv docker 12582912 Apr  3 21:17 ibtmp1
drwxr-x---  2 guest-okauxv docker     4096 Feb 23 22:35 mysql
drwxr-x---  2 guest-okauxv docker     4096 Mar 25 16:58 NodeRestDB
drwxr-x---  2 guest-okauxv docker     4096 Feb 23 22:35 performance_schema
drwxr-x---  2 guest-okauxv docker    12288 Feb 23 22:35 sys
drwxr-x---  2 guest-okauxv docker     4096 Mar 29 10:34 testDB
drwxr-x---  2 guest-okauxv docker     4096 Mar  1 11:52 demoDB

从这看起来,我(好船坞人)设法改变了mysql目录中所有目录的所有者和组。

我是否需要完全重新安装MySQL服务器?

解决此问题的最简单,最简单的方法是什么?

非常感谢您的帮助。

已更新为FIX

  

正如Andy Shinn在第一点所说的那样,我只是运行sudo chown -R mysql:mysql /var/lib/mysql来更改所有者并启动mysql   通过运行sudo /etc/init.d/mysql start和mysql返回

     

[ ok ]Starting mysql (via systemctl): mysql.service.

1 个答案:

答案 0 :(得分:5)

还需要更多信息。但有两件事情会浮现在脑海中。

  1. 很可能是许可问题。根据您的输出,为什么不先尝试将所有者和群组更改回mysql?这应该是一个简单的sudo chown -R mysql:mysql /var/lib/mysql
  2. 运行mysql:latest图像可能是您在本地运行的不同版本的MySQL,它可能已将MySQL数据升级为更新的格式,这可能与旧版本不兼容。检查您在本地运行的MySQL版本是否与mysql:latest图像标记指向的版本相同(至少是相同的次要版本,例如5.6和5.6)。
  3. mysql:latest是什么版本以及您在本地运行的版本是什么?你有从你开始的MySQL容器的任何日志输出吗?