I am trying to connect to a mysql db on a shared server. I am using a java application to make the connection. Problem doesn't happen when I connect to localhost db.
URL = "jdbc:mysql://SHARED HOST IP:3306/DBNAME";
USER = "dbUSER";
PASS = "dbPASS";
Connection conn = DriverManager.getConnection(URL, USER, PASS);
java.sql.SQLException: Access denied for user 'DBUSER'#'mycomputersIP???' (using password: YES)
It is strange that it says denied for dbuser# mycomputersip instead of dbuser#sharedhostIP
Is there a setting on my wireless router that is screwing things up?
your database is not configured for remote access. basically its saying your user located at your ip doesn't have permission to access the database, as opposed to your user located at the web server.
if you are using a shared hosting package, you will either need to turn this on in your admin area, or it may not be supported by your host. some hosts additionally require that externally accessible databases may not be on the web server, so your connection string would likely change as well.
There are no settings screwed up on your router. If you are trying to connect from mycomputersIP (i.e. the program opening the JDBC connection is on your computer), then the database will need to grant permission to 'DBUSER'#'mycomputersIP'. (In fact, that is the point of that portion of the grant string.)
Just as VeeArr said, 'DBUSER'#'mycomputersIP???' is standard. For some reason your host exposes your database but isn't allowing you to connect. There's a way in phpMyAdmin to do it under Privileges if you manage the whole database or there's an option in your control panel. If not, then you need to contact your host for guidence
The Same problem I have got earlier, Its very simple, The access has been denied by your ISP to access DB,
Raise the request to grant access, it will work.
Related
I've made a Mysql db that i can easily manipulate with Java,
However I cant access it from other machines since its running off localhost only right? How would i go about making it so i would be able to manipulate the data from another machine. Or am i going about this all wrong? I've tried playing around with the remote access on MySQL workbench but I'm just not understanding it.
Here is how I'm accessing it currently.
Connection myConn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sampledatabase"
);
Of course you could access it remotely!
Firstly, you must understand what's a MySQL user and the authentication mechanism. MySQL treat 'UserName'#'Host' as a real user who can access to the MySQL server. When you access it locally the actual user you used is 'Me'#'localhost' (Assume the username here is 'Me'). And inside MySQL server there must be a user named 'Me'#'localhost' exist(or 'Me'#'%'). You must provide the right password for 'Me'#'localhost' as well.
When you need to access it remotely, you must replace localhost with the remote ip address so that your app could create the TCP connection correctly. Assume that the ip address of MySQL server is 172.0.1.5 and the ip address of your app is 172.0.1.10. The actual user you used now is 'Me'#'172.0.1.10'. You must make sure that the user 'Me'#'172.0.1.10' does exist in MySQL server. Otherwise you will encounter a auth failure.
To check all users:
select * from mysql.user; // if you have the privilige to perform it
Add users: Create User Syntax.
Yes, you can access the database, which is installed on other machine. You need to understand the url, which you provided
jdbc:mysql://localhost:3306/sampledatabase
Here localhost refers to hostname of the database server, mean same machine or local machine. If you are trying to access some other database server, which resides on other machine, then you need to replace localhost with remote-machine-hostname or it's ip-address.
Suppose, I have a website for a school to collect students information and data.And my site has a MySQL databse.So how can I or my desktop application get those data from my site's database?Basically, when I use MySQL for my desktop application I write some line of codes to connect with my local MySQL database which is given below.
public settingdatabase(){
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rgacd","root", "");
stat = con.createStatement();
}catch(Exception ex){
System.out.println("Error: "+ex);
}
}
But when I try to connect with any HTTP site's database throough my desktop application what should I do.
Thanks In Advance. :D
Typically there are firewalls involved. Many networks running web servers will only accept incoming http/https connections (ports 80 and 443). Other ports (such as 3306 to connect to a mysql database) are closed to the outside world. The web server for the site often connects to an application server (e.g. Tomcat) that has network privileges to access the internal database.
So the simple answer is usually you can't directly connect to the database backing any arbitrary website because you don't have access to it.
Here is a somewhat typical architecture courtesy of Tivoli and an IBM slide deck:
By design, in most cases, direct access to the RDBMS is simply inaccessible to the users outside the firewall.
Now, in the unusual case that the firewall allowed an open port to connect to the database from any external machine, then you could connect to the machine via a jdbc network connection (the same as you are doing by accessing the database over localhost:3306). To establish such a connection you would need to use the publicly available address of the database machine (which may or may not be the same as the address used for the http connection, depending upon the network configuration of the system).
I have three servers, App Server, Domain Controller and SQL Server. All of them are connected trough the local network.
What I am trying to accomplish is to successfully connect my app to the database using the credentials of an authorized domain user (ex: dom\dbadmin).
When I connect locally using those credentials, it works.
When I run the next code trough CMD on the APP Server with the right credentials and local IP, it works!
RUNAS /user:dom\dbadmin /netonly "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe"
But when I try to connect with my app to the database with the following connection string it does not connect.
jdbc:sqlserver://10.20.30.110\MSSQLSERVER;databaseName=dBase;user=dom\dbadmin;password=!8899#te$t;
I have successfully made a connection to a identical DB but with SQL credentials and a remote ip and it works.
Am I doing something wrong? Or is it just not possible to make a connection with JDBC and domain credentials?
As far as I know - for passthrough authentication to work (SSPI in connection string) - you'll have to allow the domain controller to make the decision to allow you in with your credentials or not. In order to make this decision the controller will reply on your windows authentication with all imposed security restriction on computers within that domain. If you are logged on a computer as CORP\UserName then SSMS will not allow you to connect as someone else such as MyDomain\OtherUser. That is even if you know the correct password.
If you need an application to connect to an SQL Server you'll probably have to enable mixed authentication on the SQL Server and then generate an application password (not relying on Windows authentication).
I need to connect to a mysql database across a network.
The connection string ive given is
"jdbc:mysql://host/dbname"
i can access the site across the network but the only problem is with the java database connection.
Ive updated the phpmyadmin.conf file giving
# Deny from all
Allow from all
But still the database connection cannot be made.
Please help me..
I don't know much aboud phpmyadmin, but what I did to configure a remote db:
The connection string is: jdbc:mysql://host:port/dbname
The port is 3306 by default
The mysql user is often name#localhost, you need to configure a user for the remote (client) machine (IP address, hostname, wildcard)
HTH
Ok, there are few things you need to check ...
1) If your database got username/password
2) Have you restarted your server after altering phpmyadmin.conf?
3) Make sure you are connecting to the correct port. Ex: mysql://host:port/dbname (if port differs from default.
4) make sure that the PC that have the DB allows incoming connections through the port.
If you still facing problems, try disabling your antivirus/firewall on the PC that have the DM and try.
I have developed an application in java that access remote mysql database. While I am running it by netbeans IDE of system which have running that wamp server. But while i try I make connection in another system to remote system database by netbeans it shows following error.
Unable to add connection, Cannot establish a connection to jdbc:mysql://192.168.1.14:3306/test using(CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
Please, kindly help me.
Thanks in Advance
From mysql forums
You could be getting this because (1) the URL of the DB is wrong, because (2) the DB isn't set up to accept connections from the web host, or because (3) some intermediate networking component is misconfigured. (1) is your problem; (2) and (3) might be your problem or the web hosting's problem, depending on where the DB is located, what administrative privileges on the DB that you have, and how the networking is set up.
You need to have the right privileges to be able to connect to MySQL remotely. There are several tools available to set it up.
Here is an article outlining several steps of which the grant step is most commonly needed.
mysql> GRANT ALL ON foo.* TO bar#'202.54.10.20' IDENTIFIED BY 'PASSWORD';
There has also been problems reported when connecting to MySQL databases in Windows Vista, but i'm not sure wether this is relevant to this case or not.
Do you have ssh access to the server? I would have run a tunnel with ssh, plink or putty (ssh -L 3305:127.0.0.1:3306 192.168.1.14) and then use this connection url
jdbc:mysql://127.0.0.1:3305/test
It would be easier to assist if we'd known your operating system.
If this is a deployment situation, opening the firewall for port 3306 from your IP address is probably the right thing. In linux you might find the settings in /etc/sysconfig/iptables, but your sysadmin may have other safe guards in place. You must also verify that mysql is actually listening on the IP-address, and not only localhost.
MySQL is standard protected so you can't access it remotely. You'll have to grant MySQL as well as the user connecting to MySQL access from outside the MySQL-machine.
Perhaps a low-level network issue.
Can you ping that IP ?
Can you telnet to that IP/port ?
e.g. telnet 192.168.1.14 3306
Establishing whether you can talk to the machine and whether you can create a basic TCP connection to the MySQL process on that machine will tell you a lot - is your network sound, is a process listening on that port etc.