简体   繁体   中英

Connecting to MySQL from Java to WAMP / MAMP Pro

I am trying to connect from java to a MySQL database from an external computer on a machine hosting WAMP and other hosting MAMP Pro. The connection to WAMP is fine but on MAMP Pro, I get the following error.

              String userName = "user";
              String password = "pass";
              String url1="jdbc:mysql://<IP Address>:3306/dbname";
              Class.forName ("com.mysql.jdbc.Driver").newInstance ();
              conn1=DriverManager.getConnection (url1, userName, password);


The last packet sent successfully to the server was 0 milliseconds ago. 
The driver has not received any packets from the server.

I had changed the privellages in both the server by going to Privellages in PhpMyAdmin and chaning host to any host under Login Information. Worked for WAMP but didn't work for MAMP Pro.

Any suggestions?

I'm answering my own question but after some struggle I found the solution. Hopefully it will help people like me in future.

I opened MAMP Pro and on Server - General tab I clicked

File => Edit Template => MySql my.conf and changed 
line no 37 from 
bind-address=127.0.0.1 to bind-address = <my server's IP Address>

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