Cannot connect mysql workbench to remote database - java

I have a remote mysql database on mydomain.com power by goDaddy and have a database name "arsenal101" with several tables and I have assigned the user "arsenal101" with password "22216888" with full privilege to that database.
In my local MySQl workbench in Macbook, I try connecting my MySQL workbench to that remote database.
Here is the screenshot
The hostname I enter mydomain.com
The username is arsenal101
The password is 22216888
The default schema is blank.
After I pressed test connection, an error message showed up " Failed to Connect to MySQL at mydomain.com: 3306 with user arsenal101
access denied for user arsenal101#xxxxxxx (using password Yes)

You should check if GoDaddy allows you to do a remote connection to the database because a lot of hosting companies don't allow that. Their MySQL has to be configured to receive external connections.

According to here: https://in.godaddy.com/help/connect-remotely-to-databases-4978
If you want to connect remotely to a database, you must enable Direct Database Access when setting it up1 — you cannot enable it later.

Related

Connect to remote H2 Database in intellj idea

I have an application running on a server and I'm using H2 database for that,
This my database URL:
jdbc:h2:./cafeDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=7080
And I want to connect to this database using Intellj idea's database tools, this is my configuration:
But when I try to connect, It keeps asking me the DB's username and password, and even when I put the correct information and submit it says:
The specified database user/password combination is rejected: [28000][28000] Wrong user name or password [28000-200]
Am I doing something wrong?

How to allow to connect MySQL via internet?

I have a MySQL database which i access through Java JDBC and it works correct in my local network(using localhost or 192.168.*.* local adress). But i also want to access it remotely from internet and when i connect to it using my global adress 176.214.186.243 (it is dynamyc adress but it stays still for 2 days of my tries) i get next error com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
In MySQL workbench i have priveleges showed on Picture(All ot them.
But i still cant connect to database using global IP.
What am i doing wrong?
mysql restricts access for any combination of user, table and remote address. In your case the user most likely can access everything locally, but not from extern (e.g for root this would be a good thing). This can be changed by:
GRANT ALL ON <database>.* TO 'client'#'%.%.%.%' IDENTIFIED BY '<a password for external usage>';
FLUSH PRIVILEGES;
<database>.* grants access to alle tables in <database>
I already added your username which seems to be client
%.%.%.% means any IP Adress where the 1.-4. digit can be anything
maybe you can limit the range of IPs or use a FQDN instead
<a password for external usage> is just for this connections and can be something else.
More infos here
you should grant the specified user the privilege to access from a certain IP address like:
GRANT [privileges|ALL PRIVILEGES] ON schema.table TO 'username'#'hostname'
IDENTIFIED BY 'password'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
privileges can be operation names like select, drop and ... or if you want to grant all the privileges to a user set "ALL PRIVILEGES"
schema.table can just specified a single table or it may be something like . to support all the schemas and tables.
username which is also called role is abvious but it can be % to grant all the users the given privileges.
hostname can be ip or host name or as like as username can be % to grant the specified users the given privileges.
for further information use can follow https://dev.mysql.com/doc/refman/8.0/en/grant.html, https://stackoverflow.com/a/6239145/2137378
The mysql documentation is much more prefered. check you mysql version and continue the exact versions documentation on mysql.
Definitely, above descriptions are to let the mysql engine know its remote users and if there is some obstacles between these two like firewall should be resolved somehow. e.g. if you are on ubuntu you can check if the firewall is the main problem by disabling it using:
sudo ufw disable
After disabling the firewall and granting the privileges, remote access was ok then you know the firewall is the issue. to enable if use:
sudo ufw enable

Unable to connect to mysql jdbc database

I am frustrated seeing this error and not knowing the solution. I am trying to connect to a mysql db with a server url but it is giving my mysqlException(stacktrace below). The code works fine till here:
String dbUrl = "jdbc:mysql://server_url/db_name";
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
String user = "user";
String password = "password";
conn = DriverManager.getConnection(dbUrl,user,password);
This is the error I'm getting
java.sql.SQLException: null, message from server: "Host '172.23.251.154' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1070)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
Is this because I'm using a different version of mysql-connector jar?
Please help me.
From Chapter 6. SQL Questions: How Do I Enable TCP Connections to MySQL?,
By default, MySQL won't allow ANY users access to any of the databases if they connect over a TCP connection. In order to permit the connection, you must create a entry in the user table of the mysql database (make sure you select the PASSWORD function to encrypt your password). In particular, the Host field needs to indicate which host(s) are permitted to connect. If you specify % (which I would not recommend), then a user would be able to connect from any host.
What about firewall on port 3306?
May be the user you are trying to access doesn't have enough privileges to access the database from the given server.
So try providing GRANTS to the user.
GRANT ALL PRIVILEGES ON database_name TO 'user'#'hostname' IDENTIFIED BY PASSWORD <password>;
FLUSH PRIVILEGES;
here hostname can be your host address "172.23.251.154". Dont forget to flush privileges and then try connecting the server.
If your MySql server is located on your host provider there is option in your control panel where you can set ip addresses from which you can connect to mysql server in your case 172.23.251.154 if this is your ip address

How to access mysql database from remote system having different ip series

My MySQL server is installed in X.X.60.X and accessing it through JDBC from X.X.80.X . I can connect it through MySQL workbench but when connect through the program it shows the following error message.
java.sql.SQLException: Access denied for user 'user'#'X.X.80.X' (using password: NO).
I have given all privileges to 'user'#'X.X.80.X in the server.
Is the password for user 'user' set in you MySQL server? If yes, check your programm, is's not using password:(using password: NO)

MySQL not able to connect from remote client

I have my MySQL server running on machine with IP address 181.2.3.5, and I have a database called affablebean running on it. I am able to connect via from same machine. But when I try to access it remotely to deploy java application but I am getting below error:
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Access denied for user 'root'#'181.2.3.4' (using password: YES)
Both systems are on LAN. I tried below queries to grant privellages:
GRANT ALL ON *.* to 'root'#'%' IDENTIFIED BY 'sql123';
flush privileges;
also below thing:
GRANT ALL ON *.* to 'root'#'181.2.3.4' IDENTIFIED BY 'sql123';
flush privileges;
But still I am getting same error, I tried restarting mysql service but still it's not accepting connections.
Btw Server is running Windows XP and client is running on Windows 7. I also tried below query:
mysql> use mysql;
mysql> SELECT host FROM user WHERE user = 'root';
it returns my ip address correctly. But still same error. Can anyone guide me? I tried above solutions from various SO questions.
Note: Above IP address and user name are just a place holder to illustrate.
Edit: I am able to access from Workbench, but I am not able to access from Java program.
You have to specify the port name with your server IP.
Like hostIP:portNumber
Workbench and your java programs are like any other clients. So what you need to see if there are any settings difference in between these two clients, maybe wrong credentials.

Categories