度娘也不给力,只好自己研究了。
先把结论写出来吧。把pid文件换个位置,就好了。
问题是, mysqld.servce的文件是从mysql的安装目录拷贝的,导致没有怀疑pid文件位置的问题。一开始还怀疑是不是自己在一些文件里拼写有误。
后来,偶然发现,/var下面的run并不是一个实际的目录(链接到 /run)。关键地方是,用 df 命令查看,/run目录的是 tmpfs的。
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 41152832 10103228 28936120 26% /
devtmpfs 498860 0 498860 0% /dev
tmpfs 131072 0 131072 0% /dev/shm
tmpfs 508196 324 507872 1% /run
tmpfs 508196 0 508196 0% /sys/fs/cgroup
tmpfs 101640 0 101640 0% /run/user/0
说明:编译之后的目录中 /usr/local/mysql/usr/lib/systemd/system/mysqld.service 拷贝到/usr/lib/systemd/system/mysqld.service
(这里提一下,另一个事,根本问题没啥关系。原来的根目录下的一些目录,都挪到了 /usr 下了。从哪个版本起,我记不住了。)
先说解决的步骤,随后贴上有关问题。
1,修改 mysqld.service 中的pid文件的位置(2处)。比如放置到mysqld的运行目录(不用重新 chown了),创建方法略。
2,运行 systemctl daemon-reload
3, systemctl start mysqld 。
4,reboot系统后,验证 问题解决。
如果没有步骤2,提示:
# systemctl start mysqld
Warning: mysqld.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
有问题时:
# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Sat 2017-07-15 22:58:50 CST; 37s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Jul 15 22:58:50 jlsky systemd[1]: mysqld.service: control process exited, code=exited status=1
Jul 15 22:58:50 jlsky systemd[1]: Failed to start MySQL Server.
Jul 15 22:58:50 jlsky systemd[1]: Unit mysqld.service entered failed state.
Jul 15 22:58:50 jlsky systemd[1]: mysqld.service failed.
Jul 15 22:58:50 jlsky systemd[1]: mysqld.service holdoff time over, scheduling restart.
Jul 15 22:58:50 jlsky systemd[1]: start request repeated too quickly for mysqld.service
Jul 15 22:58:50 jlsky systemd[1]: Failed to start MySQL Server.
Jul 15 22:58:50 jlsky systemd[1]: Unit mysqld.service entered failed state.
Jul 15 22:58:50 jlsky systemd[1]: mysqld.service failed.
问题解决后:
# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2017-07-15 23:03:18 CST; 1min 18s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 1503 (mysqld)
CGroup: /system.slice/mysqld.service
└─1503 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.495016Z 0 [Note] IPv6 is available.
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.495025Z 0 [Note] - '::' resolves to '::';
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.495043Z 0 [Note] Server socket created on IP: '::'.
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.775356Z 0 [Note] Event Scheduler: Loaded 0 events
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.823217Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: Version: '5.7.18' socket: '/tmp/mysql.sock' port: 3306 Source distribution
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.823232Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a l...is check.
Jul 15 23:03:17 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:17.823234Z 0 [Note] Beginning of list of non-natively partitioned tables
Jul 15 23:03:18 izj6c2quobtad9dwb7gspkz mysqld[887]: 2017-07-15T15:03:18.108745Z 0 [Note] End of list of non-natively partitioned tables
Jul 15 23:03:18 izj6c2quobtad9dwb7gspkz systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.