今天在linux下部署一個 JavaEE項目的時候老是鏈接不到Mysql數據庫,檢查以後發現鏈接池的配置肯定是對的,進入linux服務器以後以mysql -uname -ppassword鏈接老是報Access denied for user 'root'@'localhost' (using password: YES」),最終解決掉這個問題以後仍是鏈接不上(參考:http://www.cnblogs.com/qlqwjy/p/8315802.html)。html
解決掉以後經過在本地的sqlyog鏈接都報錯,但是在linux服務器上能夠運行,用下面語句受權以後仍是鏈接不上,而且Java程序也是鏈接不上mysql
受權:linux
mysql> grant all privileges on *.* to 'root'@'%' identified by 'admin'; mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'admin'; mysql> flush privileges;
查看登陸用戶信息:sql
mysql> select user,host,password from mysql.user;
此時用service myqld stop發現不起做用,也就是關不掉mysql服務,用service mysqld start啓動報錯:數據庫
Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
最終經過查看mysql的錯誤日誌發現mysql服務一直開啓着:服務器
mysql> show variables like 'error_log'; Empty set (0.00 sec) mysql> show variables like 'log_error'; +---------------+---------------------+ | Variable_name | Value | +---------------+---------------------+ | log_error | /var/log/mysqld.log | +---------------+---------------------+ 1 row in set (0.00 sec) mysql> quit Bye [root@iz2ze46xi6pjjj69ailg9lz logs]# cat /var/log/mysqld.log
錯誤日誌:socket
180119 10:01:35 mysqld_safe Logging to '/var/log/mysqld.log'. 180119 10:01:35 mysqld_safe A mysqld process already exists 180119 10:01:37 mysqld_safe Logging to '/var/log/mysqld.log'. 180119 10:01:37 mysqld_safe A mysqld process already exists 180119 10:01:38 mysqld_safe Logging to '/var/log/mysqld.log'. 180119 10:01:38 mysqld_safe A mysqld process already exists
解決辦法:最後是經過查看mysql相關的pid而後殺死進程以後從新啓動mysql解決的:ide
[root@iz2ze46xi6pjjj69ailg9lz logs]# ps -ef|grep mysql mysql 24359 1 0 10:31 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr mysql 24541 24359 0 10:31 ? 00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock root 25420 25023 0 11:17 pts/2 00:00:00 grep --color=auto mysql [root@iz2ze46xi6pjjj69ailg9lz logs]# kill -9 24541 [root@iz2ze46xi6pjjj69ailg9lz logs]# kill -9 24359
經過上面命令查看到mysql相關的進程id以後殺掉進程,重啓mysql服務發現一切正常。ui
[root@iz2ze46xi6pjjj69ailg9lz logs]# service mysqld start