MySql全套攻略——添加新用户、为用户创建数据库和给用户分配权限

1.添加新用户
只允许本地IP访问
[html] view plain copy
  1. create user 'test'@'localhost' identified by '123456';  

允许外网IP访问

  1. create user 'test'@'%' identified by '123456';  
刷新授权
  1. flush privileges;  

2.为用户创建数据库

  1. create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;    

3.为用户分配权限

授予用户通过外网IP操作该数据库的所有去权限

  1. grant all privileges on `testdb`.* to 'test'&'%' identified by '123456';  

授予用户通过外网IP操作所有数据库的权限

[html] view plain copy
  1. grant all privileges on *.* to 'test'&'%' identified by '123456';  

刷新授权

  1. flush privileges;  

猜你喜欢

转载自blog.csdn.net/weixin_38368982/article/details/80722252