linux下程序JDBC连接不到mysql数据库
Posted Qiao_Zhi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下程序JDBC连接不到mysql数据库相关的知识,希望对你有一定的参考价值。
今天在linux下部署一个 JavaEE项目的时候总是连接不到mysql数据库,检查之后发现连接池的配置确定是对的,进入linux服务器之后以mysql -uname -ppassword连接总是报Access denied for user \'root\'@\'localhost\' (using password: YES”),最终解决掉这个问题之后还是连接不上(参考:http://www.cnblogs.com/qlqwjy/p/8315802.html)。
解决掉之后通过在本地的sqlyog连接都报错,可是在linux服务器上可以运行,用下面语句授权之后还是连接不上,并且Java程序也是连接不上
授权:
mysql> grant all privileges on *.* to \'root\'@\'%\' identified by \'admin\'; mysql> grant all privileges on *.* to \'root\'@\'localhost\' identified by \'admin\'; mysql> flush privileges;
查看登录用户信息:
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
错误日志:
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解决的:
[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服务发现一切正常。
[root@iz2ze46xi6pjjj69ailg9lz logs]# service mysqld start
以上是关于linux下程序JDBC连接不到mysql数据库的主要内容,如果未能解决你的问题,请参考以下文章
找不到适合'jdbc:mysql:// localhost:3306 / mysql的驱动程序[重复]