I am aware of this command:
GRANT ALL PRIVILEGES
ON database.*
TO \'user\'@\'yourremotehost\'
IDENTIFIED BY \'newpassword\';
But then it on
Open your mysql console
and execute the following command (enter your database name,username and password):
GRANT ALL ON yourdatabasename.* TO admin@'%' IDENTIFIED BY 'yourRootPassword';
Then Execute:
FLUSH PRIVILEGES;
Open command line and open the file /etc/mysql/mysql.conf.d/mysqld.cnf
using any editor with root privileges
.
For example:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Then comment out the below line:
bind-address = 127.0.0.1
Restart mysql to reflect the changes using command:
sudo service mysql restart
Enjoy ;)
TO 'user'@'%'
% is a wildcard - you can also do '%.domain.com'
or '%.123.123.123'
and things like that if you need.
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.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
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
bind-address = 127.0.0.1
Restart your mysql using
sudo service mysql restart
Now you should be able to connect remotely to your mysql.
If you are running EC2 instance don't forget to add the inbound rules in security group with MYSQL/Aurura.
You need to change the mysql config file:
Start with editing mysql config file
vim /etc/mysql/my.cnf
add:
bind-address = 0.0.0.0
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.