mysql数据库连接失败问题排查

今天连本地数据库,报无法连接的错

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

查询资料,说是要把mysql的配置文件中的bind-address注释调

# bind-address = 127.0.0.1

然后重启即可。

然而在重启时报错:

c80k2@c80k2-Vostro-3667❯/etc/mysql/mysql.conf.d$ sudo /etc/init.d/mysql restart
[....] Restarting 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!
c80k2@c80k2-Vostro-3667❯/etc/mysql/mysql.conf.d$ sudo service mysql restart
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

提示查看"systemctl status mysql.service" and "journalctl -xe" 获取详情。

c80k2@c80k2-Vostro-3667❯/etc/mysql/mysql.conf.d$ 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 二 2018-03-06 10:42:52 CST; 19s ago
  Process: 23472 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 23464 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 23472 (code=exited, status=1/FAILURE);         : 23473 (mysql-systemd-s)
   CGroup: /system.slice/mysql.service
           └─control
             ├─23473 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─23516 sleep 1

3月 06 10:42:52 c80k2-Vostro-3667 systemd[1]: Starting MySQL Community Server...
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:52.949388Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:52.949501Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:53.097114Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:53.098086Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-0ubuntu0.16.04.1-log) starting as process 23472 ...
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:53.099329Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server s
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:53.099344Z 0 [ERROR] Aborting
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:53.099356Z 0 [Note] Binlog end
3月 06 10:42:53 c80k2-Vostro-3667 mysqld[23472]: 2018-03-06T02:42:53.099385Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
3月 06 10:42:53 c80k2-Vostro-3667 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
 ESCOC

看到有这么一句:You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server s...

你已经开启了binary log日志,但是没有提供强制的server-id.

进mysql配置文件 vim /etc/mysql/mysql.conf.d/mysqld.conf,将server-id打开

server-id               = 1

再次重启mysql即可使用。

猜你喜欢

转载自my.oschina.net/u/3412738/blog/1630632