【提示】本文写作命令为:abysw blog mysql重启服务器后再次失效
几乎每次重启后,mysql都会报错,所以要专门记录一下。
服务器:Dell,x86-64
系统版本:
$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
问题描述:
failed: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
==============================================================================
先排错:
$ mysqld start
2022-06-04 10:11:07 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-04 10:11:07 0 [Note] mysqld (mysqld 5.6.51) starting as process 70395 …
2022-06-04 10:11:07 70395 [ERROR] Fatal error: Please read “Security” section of the manual to find out how to run mysqld as root!
2022-06-04 10:11:07 70395 [ERROR] Aborting
2022-06-04 10:11:07 70395 [Note] Binlog end
2022-06-04 10:11:07 70395 [Note] mysqld: Shutdown complete
$ service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
$ service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-06-04 10:18:16 CST; 33s ago
Process: 164973 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 164826 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 164972 (mysqld_safe)
Tasks: 23
CGroup: /system.slice/mysqld.service
├─164972 /bin/sh /usr/bin/mysqld_safe –basedir=/usr
└─165223 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib64/mysql/plugin –log-e…
Jun 04 10:18:15 xu171 systemd[1]: Starting MySQL Community Server…
Jun 04 10:18:15 xu171 mysqld_safe[164972]: 220604 10:18:15 mysqld_safe Logging to ‘/var/log/mysqld.log’.
Jun 04 10:18:15 xu171 mysqld_safe[164972]: 220604 10:18:15 mysqld_safe Starting mysqld daemon with databases from /…/mysql
Jun 04 10:18:16 xu171 systemd[1]: Started MySQL Community Server.
Hint: Some lines were ellipsized, use -l to show in full.
$ rm /tmp/mysql.sock
$ ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
好了,可以用了。
总的来说操作如下:
切换到root目录,然后输入以下命令,注意看mysql状态是不是激活,激活了是绿色提示,未激活是红色提示。
1 | service mysqld restart |
*** 颜色命令还没调试好,没心情截图 ***