最近在macos中通过brew install mariadb@10.11 安装后, 在通过 brew services restart mariadb@10.11 重启居然报 mysqld_safe A mysqld process already exists 异常。
mariadb的异常日志
注意这个异常日志在所有系统中都是一样的,他位于datadir数据库文件存放目录下 名称为 机器名.err 。 这个异常日志对于排查mysql/mariadb的启动异常是至关重要的, 通过查看这个日志即可获取所有的相关异常信息。
如下示例
通过这个xx.err 异常日志文件,我们看到了导致这个文件的根源是没有正常关闭。
解决方法
通过ps aux | grep mariadb 查看相关的服务进程, 然后kill -9 pid杀死相关进程后再start启动服务
➜ ps aux|grep mariadb
Tekin 23088 0.0 0.9 34872104 144852 ?? S 10:07上午 0:00.44 /usr/local/opt/mariadb@10.11/bin/mariadbd --basedir=/usr/local/opt/mariadb@10.11 --datadir=/opt/mariadb1011/data --plugin-dir=/usr/local/opt/mariadb@10.11/lib/plugin --log-error=/opt/mariadb1011/data/MacBook-Pro.lan.err --pid-file=MacBook-Pro.lan.pid --port=3306
Tekin 35188 0.0 0.0 34141276 944 s000 S+ 10:27上午 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox mariadb
➜ kill -9 23088
➜ brew services start mariadb@10.11
总结: mysql启动问题排查方法就是先找到异常日志,他位于数据库的存放目录中名称为 机器名.err 找到这个文件后直接cat xxx.err或者使用编辑器打开即可查看是什么原因导致的启动失败。 然后我们通过使用 ps aux|grep 服务名称 的方式查找相关的系统进程,然后使用kill -9 pid杀死相关进程, 从而根据问题原因来解决问题。