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.
Config file changes are required to enable connections via localhost.
To connect through remote IPs, Login as a "root" user and run the below queries in mysql.
This will create a new user that is accessible on localhost as well as from remote IPs.
Also comment the below line from your my.cnf file located in /etc/mysql/my.cnf
Restart your mysql using
Now you should be able to connect remotely to your mysql.
Run the following:
Then attempt a connection from the IP address you specified:
You should be able to connect.
Assuming that the above step is completed and MySql port 3306 is free to be accessed remotely; Don't forget to bind the public ip address in the mysql config file.
For example on my ubuntu server:
In the file, search for the [mysqld] section block and add the new bind address, in this example it is 192.168.0.116. It would look something like this
you can remove th localhost(127.0.0.1) binding if you choose, but then you have to specifically give an IP address to access the server on the local machine.
Then the last step is to restart the MySql server (on ubuntu)
or
#/etc/init.d/mysql restart
for other systemsNow the MySQL database can be accessed remotely by:
Open your
mysql console
and execute the following command (enter your database name,username and password):Then Execute:
Open command line and open the file
/etc/mysql/mysql.conf.d/mysqld.cnf
using any editor withroot privileges
.For example:
Then comment out the below line:
Restart mysql to reflect the changes using command:
Enjoy ;)
% is a wildcard - you can also do
'%.domain.com'
or'%.123.123.123'
and things like that if you need.You can slove the problem of MariaDB via this command:
Note:
%
is a wildcard. In this case, it refers to all IP addresses.