Lenox Xian

Everything negative-pressure,challenges-is all an opportunity for me to rise

Mysql Account privileges

16 August 2020

创建用户

mysql> CREATE USER 'your_username'@'host_ip_addr' IDENTIFIED BY 'your_pwd';

host_ip_addr 是你要从其连接到MySQL 服务器的计算机的主机名或IP地址

分配权限

mysql> GRANT ALL PRIVILEGES ON db_name.tab_name TO 'your_username'@'host_ip_addr' WITH GRANT OPTION;

db_name 是允许访问的数据库名称,* 表示任意数据库。 tab_name 是允许访问的表名称,* 表示任意表。 ALL PRIVILEGES 代表全局或者全数据库对象级别的所有权限。

刷新权限

mysql> FLUSH PRIVILEGES;

查询用户

mysql> USE mysql;
mysql> SELECT host, user, plugin FROM user;
+------------+------------------+-----------------------+
| host       | user             | plugin                |
+------------+------------------+-----------------------+
| %          | ghost            | caching_sha2_password |
| 172.17.0.% | root             | caching_sha2_password |
| localhost  | mysql.infoschema | caching_sha2_password |
| localhost  | mysql.session    | caching_sha2_password |
| localhost  | mysql.sys        | caching_sha2_password |
| localhost  | root             | caching_sha2_password |
+------------+------------------+-----------------------+
6 rows in set (0.00 sec)

如何允许远程访问MYSQL Community ( OS:Fedora )

添加新的规则到防火墙 ( Firewalld)
1
2
3
sudo firewall-cmd --permanent --zone=public --add-service=mysql
OR
sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
重启 firewalld.service
1
sudo systemctl restart firewalld.service
编辑 MYSQL Community 配置文件

编辑 /etc/my.cnf.d/community-mysql-server.cnf, 导航到以bind-address指令开头的行。将此指令设置为通配符IP地址*,::0.0.0.0

1
bind-address            = 0.0.0.0

保存重启MYSQL服务

1
sudo systemctl restart mysqld

— Lenox Xian