当前位置:网站首页>Database connection exception: create connection error, url: jdbc: mysql://ip/ Database name, errorcode 0, state 08s01 problem handling

Database connection exception: create connection error, url: jdbc: mysql://ip/ Database name, errorcode 0, state 08s01 problem handling

2022-06-23 05:26:00 Firewood boy

     Today, some interfaces have been added to the project , After the local test, package and deploy to the test environment , The database connection failed unexpectedly , The error information is as follows :create connection error, url: jdbc:mysql://ip/ Database name , errorCode 0, state 08S01, The meaning of this error message is that the database connection is abnormal , I believe many people have met , Now, I will always follow the positioning idea of this problem in remote database connection .
1. determine mysql Whether the process is running

ps -ef|grep mysqld

If not running , You can start mysql, Starting mode :

service mysql start
sudo service mysqld start 

Different installation methods have different startup commands , You can refer to : Super detailed linux Deploy mysql5.7 Actual combat record
2. Try to connect locally mysql See if the connection is successful

win+r, Input cmd, Enter the black window command line , Enter the command :

msyql -h  The name of the server where the remote database is located ip -u root -p

Then enter the password , If you can't log in , You need to recheck the database connection information , Notice the name of the database you want to connect to 、 Whether the database port is correct ( The general default port is 3306)、mysql Whether the database allows access to only one connection ip Or all . This is mainly about the database configuration file my.cnf Configuration information in .
 Insert picture description here

     Take another look at mysql In the database user In the table host The address of , The default is localhost, That is, it can only be accessed locally , Remote connections are not allowed .
View by :

USE mysql;
SELECT * FROM USER

 Insert picture description here
host Set to %, Indicates yes root The user is at any ip Next visit . If there are no problems above , Keep looking down .
3. Alibaba cloud ecs Server security group settings
     As long as it is an application deployed in Alibaba cloud , You need to set an open port in the security group to allow access ip. In actual development , For those deployed on Alibaba cloud mysql In terms of database , You need to add two records to the database port , One is right mysql The database itself allows access to , That is, the corresponding ip Is the Alibaba cloud server address ; The other is for the specified application server ip Turn on .
 Insert picture description here

The reason for the problem here is the database port in the security group settings 3306 There is only one record , Only right java The server where the project is located ip to open up , Add a new one mysql Server ip The problem is solved after recording .
     The above is a summary of troubleshooting ideas for abnormal database connections , If it helps you, you are welcome to like your collection or leave a message in the comment area !

原网站

版权声明
本文为[Firewood boy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230335480814.html