How to make any ip address connect to the remote MySQL server? - java

Reason for asking the question:
For my third year minor project I am making an instant messenger type of application. The MySQL server for which will reside on my college's server. I have made the application in java and I am using mySQL for the back-end database.
Problem/Question:
My problem is that when I will distribute the application to my fellow students, the mysql server will be transferred to the college's server(currently everything is on my home computer, since I am developing right now), but then what I am supposed to do so that to every application remotely will be able to access this db on my college server.
I will be more specific:
This the basic code I am using currently:
Connection o =
DriverManager.getConnection("jdbc:mysql://localhost/db","root","pass");
I know when i will finally deploy the mysql db onto the server the localhost shall be replaced by the server's ip address(in each of the applications), but today when I tried to do this, I always got the error that:
"null message from server host 'theremoteip' is not allowed to connect to this mysql server"
So i went to the mysql server and applied:
GRANT ALL PRIVILEGES
ON database.*
TO 'user'#'%'
IDENTIFIED BY '%';
then i got this error:
Access denied for user 'root'#'theremoteipaddress' (using password: YES)
So, i figured that in the 'mysql' database root user may be assigned to only certain host addresses, i may be wrong but i think this is the problem.
So, I humbly request all of the veterans present on this community to please help me, I am new to all of this and I apologize if this question has an obvious answer and I didn't knew it.
Thank you for reading and please help me.
Again, the question is how I can make all the remote applications that I distribute among students to connect to the MYSQL database.

Probably for security reasons, root is allowed to login only from the same machine on which mysql server is running(or from listed ip addresses). If you ssh to your server and open mysql from there you should be able to change the permissions for your user.

Related

Java, MySql -- connecting from another computer

I created a java program that uses MySql. Now I want to give the app to someone else, and I'm using the URL as: jdbc:mysql://ipAddress:3306/tableName, but it doesn't work, showing the error of connection failure.
What should I do?
It's a troubleshooting stuff, do the following.
Check the Firewall and Port access on MySQL Server computer.
Check the MySQL Service and the DB User is doing good.
Follow the following thread
How to allow remote connection to mysql

JDBC tries to connect to "localhost" regardless of the hostname

I'm banging my head hard.
This simple line of code:
DriverManager.getConnection("jdbc:mysql://machine1:3306/information_schema", "user1", "password");
Running on machine1 results in an error:
1045 Access denied for user 'user1'#'localhost' (using password: YES)
However there's no problem running on machine2 or any other machine for that matter.
user1 actually has two different passwords, one is password if the connection is made to machine1 (which is the machine name), one is password1 if the connection is made to localhost.
That sounds crazy but our IT department insists that it is for security purposes. So if you can ignore the madness of that, the problem is obvious: I asked JDBC to connect to machine1 with username user1 and password password, which is correct, but it somehow tries to connect to localhost and hence the error.
I suspect that on machine1, there's some sort of configuration that delegates all internal connection from machine1 to localhost. That's why the error only occurs when I run that command from machine1, and never occurs if I run it from elsewhere.
Modify the code to connect to localhost will work but the framework does not allow me to do that.
Any idea?
I hate this when I bang my head against the wall for 5 hours and the moment after I post the question on SO I find the answer.
The problem is that in /etc/host, machine1 points to the same address as localhost (127.0.0.1). Modify the file to have machine1 point to the real IP address (e.g. 10.240.3.167) will solve the problem.
Are you running this code on machine1? In that case the error is correct because localhost is itself. Have you tried connecting via the MySQL command line from the same machine running your code? I suspect the credentials aren't set up in MySQL to allow connections from localhost.
I just re-read. You need to use the localhost password when connecting from machine1. MySQL uses #localhost as where the connection is coming from. What value jdbc used for dns is not relevant.

mysql cpanel netbeans remote connection

hello guys i have seen similar threads concerning my question but couldn't solve my problem. i am trying to remotely connect to the mysql database hosted on cpanel through my netbeans. i have added my ip address as a host to be allowed remote access. the cpanel ip address was given as https:197.211.45.2:2087. the username given as 'root' and the password also given. in my netbeans i try connecting to the database using the stated parameters and the database name but it wouldnt just connect. i have also tried using the default mysql port it still wouldnt work. if there is anything wrong i have done please put me aright. thanksthe image.. i have attached a snapshot. thanks
It's seems that MySQL port is not added in server firewall and due to that you are getting this issues. Please add port 3306 in firewall and check again.
Under cPanel there is usually 'Remote MySQL' tool which allows you to enter the IP addresses that are allowed to connect into the host.

java application not connect with a specific database in mysql on localhost,connection refused error comes

My java application is not connect with a specific database in MySQL on local host.'Connection refused' named error coming when I am trying to connect.
I have checked also service of MySQL its working because there is two db on local host, I am able to connect with one Db. I have googled all the things but my problem still not resolved.
Please check the Bind address
(https://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_bind-address) to see if you have altered the my.cnf|ini configuration file on mysql correctly.
Also if you are trying to connect using different machine then you have to create a user and grant him privileges like this to make the database available remotely
CREATE USER 'jeffrey'#'%' IDENTIFIED BY 'mypass';
GRANT ALL ON db1.* TO 'jeffrey'#'%';
Wildcard % is used to give access to any IP connecting your machine.

JDBC: Oracle Application Server and "The Network Adapter could not establish the connection" error

I am getting the error: "The Network Adapter could not establish the connection" from a web application deployed in Oracle Application Server 10g. The database is local, so there shouldn't be any connection issues.
First test: I can connect to the DB no problem from SQL plus, run queries, etc.
Second test: I can connect to the database no problem from a locally installed JDeveloper on the server, and run queries, etc. no problem. This works with the short JDBC scring, and the long one (shown below).
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=abcd)(SERVER=DEDICATED)))
Yet when I run the web app, it gives the above error. It seems too generic for me to do anything about.
Any suggestions on how to solve this? I assume that Oracle logs failed connection attempts somewhere, but I couldn't find anything relevant in the databases alert.log file.
It is possible that the problem is that the application is using an old jsdk, but I would assume that then some version mismatch error would be given instead of a "network connection" message.
Edit: I don't know whether this is an OAS problem or a problem with the specific Web Application, I would like to figure this out first, as it seems it should be easy. In WebSphere, there is a "test connection" button to dest data-sources you have added, but it seems there is no such functionality in OAS10? Somehow I think there must be, and I am just missing it because I am not an OAS expert.
Edit 2: I installed JDevelop on a remote machine and connected to the database with no problems, so I know for sure it isn't an issue with the database connectivity itself - it seems like it must be a problem within OAS?
I faced similar problem(able to connect through client but not web application) with Oracle XE when running with default configuration. Increasing number of sessions and processes solved my problem. Check this http://www.markcallen.com/oracle/oracle-xe-tuning.
I assume that Oracle logs failed connection attempts somewhere
It would show up in listener.log, but with the error you get, it seems doubtful that JDBC could even contact the listener.
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=abcd)(SERVER=DEDICATED)))
Is that the same string you use for the web app?
I've had issues with localhost and 127.0.0.1 which go away when using a more definitive host name or address [IE a name that other machines would know the host as.]. I think it was to do with how the name was resolved (eg locally or off to a name server or similar).
Not a java person, but is there any way to simply ping localhost/127.0.0.1 from the java and see whether there's a response.
One of the ways to fix the issueis to update Hosts file at WAS Server with entries for DB servers as shown below:
111.222.333.444 serverab.abc.com serverab

Categories