How to access mysql database from another host machine - mysql

I am trying to access mysql database from another host machine . My Java Application is hosted on one system and database hosted on another system .I am unable to access database from application hosted machin.
changing IP address of both machine its now working.
error occurred.
HTTP Status 500 - javax.servlet.ServletException: java.sql.SQLException: null, message from server: "Host 'IBM-PC' is not allowed to connect to this MySQL server"

The fix is root to connect to MySQL on any hosts. By default, user “root” was only allowed to connect to localhost and 127.0.0.1 hosts of MySQL.
And you can try it;
#GRANT ALL PRIVILEGES ON *.* TO ‘root’#’%’
IDENTIFIED BY ‘<roots-password>’ WITH GRANT OPTION;

Related

MySQL Server Remote Connect

I've set up a MySQL server through GCS VMs, Set up all of the required users, etc however I can't remotely connect.
I've opened the ports through firewall, given all the required permissions, made sure the server is running and just about every other method I've found so far. I checked the my.ini file (Using 8.0 on Windows 2012 R2) and found no 'bind-address' value or similar in the file.
I've assigned a static IP, ran:
"CREATE USER 'root'#'%' identified by 'password'; GRANT ALL PRIVILEGES ON *.* to 'root'#'$';"
and I'm getting the error
Cannot connect to database server...
unable to connect to...
any help to do with remote connection appreciated :)

Access Denied for User 'username'#'IP' error - digtal ocean

I've currently set up a staging area for my app in Digital Ocean with LAMP stack. The Framework for my app is Laravel 5.5 and Vue 2x.
In development, I've been using remote MySQL and had no issues with the connection error. However, when I moved it to the staging env, it is giving me access denied error. When I looked at it closely to the error log, Access denied is for username#[digital-ocean-droplet-ip], whereas I have properly configured the MySQL credentials to the remote host IP under laravel's config/database file.
So, I am doubtful if I have to do any configuration under Apache to allow any external MySQL connection? I forgot the cmd but I did allow sfw firewall allow to any port 3306 to the remote server IP address in Apache.
Any help is appreciated.
Thanks!
MySQL by default does not create an user with access from remote connections.
First you need to create an user on database that allows connection from outside (%) or a specific IP
CREATE USER 'newuser'#'%' IDENTIFIED BY 'password';
Than give him privileges
GRANT ALL PRIVILEGES ON *.* TO 'newuser'#'%';
The *s could be replaced by your database and table name respectively
You might also check if in your mysql configuration(/etc/mysql/mysql.conf.d/mysqld.cnf in my case) has this line uncommented
bind-address = 127.0.0.1
Change the ip if necessary
restart mysql and apache
sudo service apache2 restart
sudo service mysql restart
Than update the user and password at your .env file and try again!

Cannot call Remote MySQL database using SSH tunneling

I have two system where one system has the MySQL database (IP address is 192.168.0.149-running in centos) and the other has the web application (IP address 192.168.0.55-running in windows). I am calling the database from the web application remotely. I wanted to use ssh to connect with the database, so I use putty to do this.
First I run the putty and initiate the port forwarding from port 3535 to 192.168.0.149:3306.
I call from my application like this
orm.RegisterDataBase("default", "mysql", "john:john1#tcp(127.0.0.1:3535)/employee?
charset=utf8&parseTime=True")
I create a user in host MySQL database like this
mysql>create user john
mysql>GRANT CREATE,DELETE,SELECT,UPDATE ON employee.* TO 'rahul'#'192.168.0.55' IDENTIFIED
BY 'john1'
Now I run my web application. When I run it I'm getting the following error
[ORM]2017/03/01 16:18:57 register db Ping `default`, Error 1045: Access denied for user
'john'#'192.168.0.149' (using password: YES)
WORKING SCENARIOS
If I don't use the SSH and calling directly the database from the application then there is no problem for this user to access the employee database.
orm.RegisterDataBase("default", "mysql", "john:john1#tcp(192.168.0.149:3306)/employee?
charset=utf8&parseTime=True")
If I change the privilege condition like this then its working for ssh based remote database connection
sql>GRANT CREATE,DELETE,UPDATE,SELECT ON employee.* TO 'john'#'%' IDENTIFIED BY 'john1'
But I don't want to do this since it will accept the connection from all the system from the local network.I wanted to give the access to only 192.168.0.55.
Your credentials don't match.
You've granted access to 'rahul'#'192.168.0.55', but you're connecting as 'john'#'192.168.0.149'.
Try granting access to the user that's actually connecting:
GRANT CREATE,DELETE,SELECT,UPDATE ON employee.* TO 'john'#'192.168.0.149' IDENTIFIED BY 'john1'

Remote MySQL not working in linux via cPanel

I have a database server and an application server and trying to connect my application server the remote database server using PHP.
As usual I used the following way to it in the following manner.
<?php
mysql_connect("remotedb.com", "mysqladmin", "mysqlpassword") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
But when I am trying to run this test I am getting the following error.
Warning: mysql_connect() [function.mysql-connect]: Host 'gator418.hostgator.com' is not allowed to connect to this MySQL server in /home/username/public_html/testmysql.php on line 2
Host 'gator418.hostgator.com' is not allowed to connect to this MySQL server
I have added the domain as %www.myappserver.com% to the remote server's cpanel "Remote MySQL" but still the issue persists. Can anyone tell me why am I getting this error?
Remote database username is not allowed to connect using your host. Most probably it is set to only be able to connect from "localhost", so check the details of your username on your mysql server and see the list of allowed hosts
Try this first from your local machine
$ mysql -h gator418.hostgator.com -u root -p
Enter password:
ERROR 1130: Host '192.168.1.4' is not allowed to connect to this MySQL server
If you are getting above error do the below codes
Do this in your server.
$ mysql -u root -p
Enter password:
mysql> use mysql
mysql> GRANT ALL ON *.* to mysqladmin#'gator418.hostgator.com' IDENTIFIED BY 'mysqlpassword';
mysql> FLUSH PRIVILEGES;
Also, update firewall rules to make sure port# 3306 is open on the server that is running the mysql database.
After the above changes, when you try to connect to the mysql database from a remote client, you’ll not get the “Host is not allowed to connect to this MySQL server” error message anymore.
This can be achievable from Cpanel also. Grant all permission to the user you have created. (For the particular database you want)

Connecting to MySQL on AWS via Query Browser While Outside the U.S

I am running MySQL on an Amazon AWS Instance. I was able to previously connect to the MySQL Database via MySQL Query Browser. Now I am traveling outside the U.S. and I am having trouble connecting via the Query Browser. I am able to use Terminal to create an ssh connection and then login to MySQL, so it does not appear to be a larger issue with the MySQL Database.
Has anyone else had a similar problem? Any ideas how I can fix this?
This is the error I get from the MySQL Browser
Your connection attempt
failed for user 'admin' from your host to server at
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com:3306: Can't connect to
MySQL server on 'ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com' (4)
Please: 1 Check that mysql is running on server
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com
2 Check that mysql is
running on port 3306 (note: 3306 is the default, but this can be
changed)
3 Check the admin has rights to connect to
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com from your address (mysql
rights define what clients can connect to the server and from which
machines)
4 Make sure you are both providing a password if needed and
using the correct password for
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com connecting from the host
address you're connecting from
The only possible problem I see could be #4, but I ran and re-ran this command via Terminal:
grant all privileges on *.* to 'admin'#'%' identified by '<pass>' with grant option;