I am aware of this command:
GRANT ALL PRIVILEGES
ON database.*
TO 'user'@'yourremotehost'
IDENTIFIED BY 'newpassword';
But then it only allows me to grant a particular IP address to access this remote MySQL database. What if I want it so that any remote host can access this MySQL database? How do I do that? Basically I am making this database public so everyone can access it.
Edit File:
/etc/mysql/percona-server.cnf
Append below code in file.
[mysqld] bind-address = 0.0.0.0
Create user for remote access.
All linux server works,
For MSWin c:\ Find insatallation location \ file path
You need to change the mysql config file:
Start with editing mysql config file
add:
Enable Remote Access (Grant) Home / Tutorials / Mysql / Enable Remote Access (Grant) If you try to connect to your mysql server from remote machine, and run into error like below, this article is for you.
Change mysql config
Start with editing mysql config file
Comment out following lines.
If you do not find skip-networking line, add it and comment out it.
Restart mysql server.
Change GRANT privilege
You may be surprised to see even after above change you are not getting remote access or getting access but not able to all databases.
By default, mysql username and password you are using is allowed to access mysql-server locally. So need to update privilege.
Run a command like below to access from all machines. (Replace
USERNAME
andPASSWORD
by your credentials.)Run a command like below to give access from specific IP. (Replace
USERNAME
andPASSWORD
by your credentials.)You can replace 1.2.3.4 with your IP. You can run above command many times to GRANT access from multiple IPs.
You can also specify a separate
USERNAME
&PASSWORD
for remote access.You can check final outcome by:
Finally, you may also need to run:
Test Connection
From terminal/command-line:
If you get a mysql shell, don’t forget to run show databases; to check if you have right privileges from remote machines.
Bonus-Tip: Revoke Access
If you accidentally grant access to a user, then better have revoking option handy.
Following will revoke all options for USERNAME from all machines:
If you see USAGE privilege after running REVOKE command, its fine. It is as good as no privilege at all. I am not sure if it can be revoked.
In website panels like cPanel you may add a single
%
(percentage sign) in allowed hostnames to access your MySQL database.By adding a single
%
you can access your database from any IP or website even from desktop applications.