If I have a mysql database on my own pc, I would use the following cnxn string to connect it to my java program :
String url = "jdbc:mysql://localhost:port/dbname";
But if my database is made over phpMyAdmin, what would be the connection string ?
one other note, the phpmyadmin database is not on my local pc now, it is on another one but both pc are in the same network.
Thanks for any help ..
phpMyadmin is administration web application developed on PHP platform. phpMyadmin connects to MySQL database that might be on other machine.
you need to check config.inc.php file of phpMyadmin to check the host and port of mysql database.
Once you get the IP and port of the mysql database you can connect using connect string like
jdbc:mysql://<ipaddress>:<port>/<database_created_through_phpMyAdmin>
Replace localhost with the IP of the machine that hosts your database:
String url = "jdbc:mysql://<ip_goes_here>:port/dbname";
As Rutesh mentions, this may or may not be the same machine on which phpMyAdmin runs.
Related
I am trying to create a Java application that connects to a MySQL database and I am using AWS to host it. So I created the AWS RDS instance and I got it to connect to the MySQL workbench just fine. My problem arises when I am trying to use JDBC to connect to it.
I have security groups that allow traffic from anywhere, but I also tried just allowing my IP.
I had it working when I was using a localhost but now I'm trying to move it to a server so keeping it localhost isn't an option (used localhost to test the application and such)
I made sure that my user was a remote user by doing
SELECT * from mysql.user;
And made sure that the host was a '%' and that it had all the privileges
So my code I'm trying to connect with in Java is
String connectionURL = "jdbc:mysql:/{hostname}:{port}/{database name}/?autoReconnect=true&useSSL=false";
String username = "username";
String password = "password";
con = DriverManager.getConnection(connectionURL, username, password);
Of course I have the actual host, port, and such in there just changed it for posting online.
When I try running it on Eclipse it says this java.lang.Exception: Database not found
I looked up some tutorials on AWS docs to make sure it lined up, which it all did.
Anyone have any idea why it might be connecting to MySQL workbench and not the JDBC?
I have a machine with CentOS and mysql server on it (let's call it 'Server'). And another(my desktop) machine with Debian (let's call it 'Desktop'). I tried to launch java program on Desktop machine. Application connects to Server's mysql database without any troubles.
When I finished development of this application (it's still works and connects to DB well) I tried to deploy this app to Server machine. I'v built it the app on the server and tried to launch, using database, which still hosted on Server machine. So now it seems to be local database for my application. But it fails during connection to DB using Server IP address or "localhost" or 127.0.0.1. I have only:
java.sql.SQLException: null, message from server: "Host '82.192.90.179' is not allowed to connect to this MySQL server".
In my.cnf file on Server I've set "bind-address=0.0.0.0".
PS:The most interesting thing, I do everything on server using ssh, and if I try to connect to database with "mysql" console tool, it connects OK either with -h82.192.90.179 and without -h option(seems to be localhost as a dafault)
To know it is permission issue try GRANT ALL ON . TO 'someuser'#%;
http://dev.mysql.com/doc/refman/4.1/en/grant.html
Then modify the above statement by replacing % with '82.192.90.179' should work.
If you feel difficult to connect JDBC means try using mysql workbench MySQL WORKBENCH
1.Make sure you have to host your server code to local server or public server
2.If you host Local Server means it will not work
3.Make sure your server is alive or not
DB_URL = "jdbc:mysql://localhost:portnumber/databasename"
eg.DB_URL = "jdbc:mysql://localhost:3306/cmes"
Maintain Your Session configuration like this in your server side in Web.xml
<session-config>
<session-timeout>-1</session-timeout>
</session-config>
I have installed MySQL to my local computer. I can access MySQL from my Java Application which is running on my computer.
My connection string is private String url = "jdbc:mysql://localhost:3306/mydatabase" which allows me to connect successfully. But when I deploy my application to other computers on my LAN and try to connect to my MySQL databases from the other computers I can't access my database.
As others have mentioned in the comments, you issue is your connection string: private String url = "jdbc:mysql://localhost:3306/mydatabase"
In order for you to be able to connect to your database from other machines on your LAN you will need to change localhost to your IP address. For example:
private String url = "jdbc:mysql://192.168.0.10:3306/mydatabase"
Providing that the other machines can see 192.168.0.10 they will be able to connect (with the right credentials of course!)
I have deployed a Spring application on CloudFoundry with MySQL service.
I want to connect to that CloudFoundry MySQL instance from MySQL Workbench/QueryBrowser.
Is there a way to get connection params(driver, url, username, password) for that mysql db on CloudFoundry?
try to connect with cadlecott application (vmc tunnel) to your mysql service. You can use the provided username, password and service name to your MySQL Workbench.
e.g.
vmc create-service mysql mysql-test
vmc tunnel mysql-test
Service connection info:
username : u5B3ShwOIX40c
password : p2VoxZqZQRxTz
name : d5dc313431cff4046b68798a8bba1328c
Starting tunnel to mysql-test on port 10000.
**1: none**
2: mysql
3: mysqldump
Which client would you like to start?: 1
( Select the 1st choise)
Then open the MySQL Query Browser and use the above username/password.
Set the hostname to 127.0.0.1 instead of localhost and remember to set the port number. The default is 10000.
please take a quick read though the documentation for vmc tunnelling here :- http://docs.cloudfoundry.com/tools/vmc/caldecott.html
As Nikos already pointed out, just select option one after connecting the tunnel and then use the supplied parameters to connect MySQL Workbench.
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>