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'
Related
I'm trying to establish a connection to a MySQL server on a remote host. Both machines are running RH 7.5 and MySQL 5.7.
I can connect to the server as a root user. I did that, and used it to set up a secondary user like this:
CREATE USER 'foo'#'client-ip-address' identified by 'my-password';
and then
GRANT ALL PRIVILEGES ON my-db.* to 'foo'#'client-ip-addres';
That all went fine. But to my surprise, when I tried to connect using this new user, I got an error I wasn't used to:
$ mysql -u foo -h server-ip-address -pmy-password my-db
Access denied for user 'foo'#'some-hostname-not-an-ip.com' (using password: YES)
I know the IP address of the client (where I'm connecting from), which is why I set up the user with that value in the "host" column on the server. But the client is obviously trying to establish a connection using a value for "host" that is not the IP address. Instead it's some hostname, and not an IP address at all.
Where is this value coming from? How does mysql determine its own host when it tries to connect to a remote server? In the past I've only ever seen it use the machine's own IP address.
I have a mysql database running on a VPS. I can ssh into the host and connect to mysql with no problems. I cannot connect to mysql remotely from my desktop. I have performed the following:
opened port 3306 on the firewall
added my local IP to the remote IPs accepted by mysql. This was done via CPanel
executed
GRANT ALL ON dbname.* TO username#'x.x.x.x' IDENTIFIED BY 'PASSWORD'
to tell mysql to let me connect from the specified address.
I execute the following from the command line on my desktop:
mysql -h x.x.x.x -u username -p
I get a password prompt which indicates I am past the firewall and mysql is responding. When I supply the password, it denies access:
ERROR 1045 (28000): Access denied for user 'username'#'x.x.x.x' (using password: YES)
Have I missed something?
The answer was given in the comments, so I will repeat it here to properly close the thread. alvits suspected that the remote user had not been created. It had been created but his comment prompted me to clean up the user table.
I deleted all remote users including loads that had been created by CPanel or migrated from another host. I then started from scratch doing create user and grant all and it works now.
Thanks!
I'm runnning MySQL 5.6 on DB server and trying to conect from application server. (app1.example.org)
On DB server, user#app1.example.org is registered as user.
I logged in app1.example.org (CentOS 6), and tried to connect DB server.
[mylocalmachine]$ ssh phanect#app1.example.org
...
[app1.example.org]$ mysql -u user -p -h 123.456.789.012
Enter password:
ERROR 1045 (28000): Access denied for user 'user'#'111.222.333.444' (using password: YES)
111.222.333.444 is associated to app1.example.org in DNS.
When I add a user user#111.222.333.444 to MySQL and try above again, I can successfully connect to MySQL. But I don't want to do this.
IP address is a little bit hard to remember, and it sometimes changes because I'm using Google Compute Engine for app server.
I want to add only user(s) with host specified in FQDN. Is it possible?
I'm using Google Cloud SQL as DB server, BTW.
You can make it open ,and use it through username and password of your db,else you just make your compute engine IP static ,so that it won't change .
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;
I am trying to connect to a MySQL database server (remote), but I can't. I am using an user with grant privileges (not root user). The error message is the following:
Can't obtain database list from the server.
Access denied for user 'myuser'#'mypcname' (using password: YES)
"myuser" is an user I created with grant access. This user allows me to connect locally to every database. I am using the same software versions in both hosts: MySQL Server 4.1 (server) and EMS SQL Manager 2005 for MySQL, edition 3.7.0.1 (client).
The point is that I need to connect to the remote server using a different user, not root user. So, how to make the connection?
Thanks.
You have to make sure that the remote user account matches what the server will see coming in for a connection. For instance:
grant select on dbname.* to myname#mypc;
will not work if mypc is not resolvable on the server via DNS or the hosts file. In this case, you could try either using an IP, or a FQDN:
grant select on dbname.* to myname#10.1.2.3;
grant select on dbname.* to myname#mypc.example.com;
Look in connectionstrings.com to see if you have the right connection string used for MySql.
Make sure
that your MySQL server listens not only on localhost
your user can access the server from his location. Try 'myuser'#'%' in the GRANT command.
//EMS manager for mysql
//this magnificient tool provide you with a way to connect to such a server that prevents access to the server from any remote file or any way from outside world
//all you need is to have ftp access to the remote server
//in c:/program files/Ems/ you will find file called emsproxy.php
//it is what we call An (API) in programming world
//upload that file to your remote server
//then when you connect with EMS you select tunnling -->checkbox
//it will ask you on the next step to provide a full url of your emsproxy.php
//i tested that process myself. i did not have access to cpanel nieghter phpmyadmin
//thanks