How to grant remote access permissions to mysql server for user?
If I do SHOW GRANTS
in my mysql database I get
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'
IDENTIFIED BY PASSWORD 'some_characters'
WITH GRANT OPTION
If I am not mistaken, root@localhost
means that user root
can access the server only from localhost
. How do I tell MySQL to grant root
the permission to access this mysql server from every other machine (in the same network), too?
Solution 1:
This grants root access with the same password from any machine in *.example.com
:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%.example.com'
IDENTIFIED BY 'some_characters'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
If name resolution is not going to work, you may also grant access by IP or subnet:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%'
IDENTIFIED BY 'some_characters'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
MySQL GRANT
syntax docs.
Solution 2:
Try:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Pa55w0rd' WITH GRANT OPTION;
Solution 3:
You need to take some steps to make sure first mysql and then root user is accessible from outside:
-
Disable
skip-networking
inmy.cnf
(i.e:/etc/mysql/my.cnf
) -
Check value of
bind-address
inmy.cnf
, if it's set to127.0.0.1
, you can change it to0.0.0.0
to allow access from all IPs or whatever ip that you want to connect from. -
Grant remote access the root user from any ip (or specify your ip instead of
%
)GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_root_password' WITH GRANT OPTION; FLUSH PRIVILEGES;
-
Restart mysql service:
sudo service mysql restart
Solution 4:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
IDENTIFIED BY 'YOUR_PASS'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
*.* = DB.TABLE
you can restrict user to specific database and specific table.
'root'@'%'
you can change root with any user you created and % is to allow all IP. You can restrict it by changing %.168.1.1 etc too.
If that doesn't resolve, then also modify my.cnf or my.ini and comment these lines
bind-address = 127.0.0.1
to #bind-address = 127.0.0.1
andskip-networking
to #skip-networking
- Restart MySQL and repeat above steps again.
Raspberry Pi, I found bind-address configuration under \etc\mysql\mariadb.conf.d\50-server.cnf