查看数据库管理员root@localhost的权限:
MariaDB [(none)]> show grants for root@localhost;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED VIA mysql_native_password USING '*41DDB5DFD213B288EE050BD64DC6AA36815A3486' OR unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
###
自定义一个数据库用户并授权:
授权用户zhuohua@'%'(密码886),可以从任意IP访问,可以对所有的库进行任意操作:
MariaDB [(none)]> grant all on *.* to zhuohua@'%' identified by '886';
Query OK, 0 rows affected (0.402 sec)
查看用户zhuohua@'%' 的权限:
MariaDB [(none)]> show grants for zhuohua@'%';
+-----------------------------------------------------------------------------------------------------------------+
| Grants for zhuohua@% |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `zhuohua`@`%` IDENTIFIED BY PASSWORD '*F961C54AFEB4D281CE53D7CB8E7822890D86FFFC' |
+-----------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
再次查看所有数据库用户及其主机信息:
mysql -uroot -p888 -e"select user,host from mysql.user;"
###
为了让远程客户端可以访问数据库,要在防火墙firewalld打开TCP 3306端口:
[root@centos8 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@centos8 ~]# firewall-cmd --reload
success
再次查看firewalld的配置文件:
[root@centos8 ~]# cat /etc/firewalld/zones/public.xml
PublicFor use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.
###
Windows客户端使用SQLyog,远程访问MariaDB数据库: