简体   繁体   中英

Cannot connect to MySQL Server using IP Address

In JDBC, when I put localhost for the url to get a connection, it works perfectly fine; I can connect to the database. However, I want other programs to be able to connect. So I tried using my IP address but that doesn't work. I already granted access to other IP addresses but it still won't connect in the Java application. What should be done to establish the connection?

Make sure it is not the MySQL bind-address problem. The parameter for bind-address in my.cnf of MySQL MySQL bind-address parameter

You will need to comment out the bind-address parameter to make sure you can connect to any of the available IP addresses. It can be one or all, it can not be multiple IP address value for this parameter.

On command line checking for which port your MySQL is listening to may help as well.

netstat -tlpn | grep mysql

i had the same problem try to disable windows and antivirus firewall give mysql access to the specific user also set mysqlhost %

example

public void addGrantMysqlAccess(String username, String password,String mysqlHost) {

    String sqlQuery="grant all on *.* to '"+username+"'@'"+mysqlHost+"' identified by '"+password+"' with grant option    ";

    ConnectivityDB.setSql(sqlQuery);
    ConnectivityDB.resultSetExecuteQueryStatement();


    ConnectivityDB.closeResultset();
    ConnectivityDB.closeStatement();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM