mysql工作中常用权限操作命令总结

权限命令总结

grant 权限名(所有的权限用all) on 库名(*全部).表名(*全部) to '用户名'@'%'(%表示所有的IP,可以只些一个IP) identified by "密码";
2)授权所有主机: grant all privileges on *.* to 'testUser'@'%' identified by '123456' with grant option; flush privileges;

3)授权指定主机: grant all privileges on *.* to 'testUser'@'192.168.22.250' identified by 'password' with grant option; flush privileges;

4)授权本地主机: grant all privileges on *.* to root@localhost identified by 'password' with grant option; flush privileges;

5)授权指定数据库: grant all privileges on testDB.* to 'testUser'@localhost identified by 'password' with grant option; flush privileges;

6)授权指定操作权限: grant select, insert, update, delete, create, drop on testDB.* to testUser@localhost identified by 'password' with grant option; flush privileges;

7)  进mysql库查看host为%的数据是否添加: use mysql; select host, user, password, Delete_priv, Grant_priv, Execute_priv from user;

8)  只读权限dump数据库: mysqldump -h 172.192.1.12 -uroot -p123456 --single-transaction your_db > your_db_bk.sql

9)  通过MySQL端口远程连接mysql: mysql -h 122.128.10.114 -P 31206 -uroot -pyg123456 // -P mysql在/etc/mysql/my.cnf 配置文件配置的端口,-p 密码

实际场景应用

我们的zabbix数据库出现下面的问题
在这里插入图片描述
这里的问题是我们的root没有访问此数据库的权限,当时mysql用的是zabbix用户
MySQL: 查看zabbix用户的权限
在这里插入图片描述
我们添加root的相关权限

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; flush privileges;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值