MySQL创建用户,并设置指定访问数据库

一、创建用户并授权

1. 登录mysql 

  mysql -u root -q
输入密码

2. 创建数据库(已有数据库就不需要建立)

create database newDB;//以创建newDB为例

3. 创建用户

创建userone,只能本地访问

 create user userone@'localhost' identified by 'password';

创建usertwo,可以远程访问

 create user usertwo@'%' identified by 'password';

4. 修改用户密码

以userone为例:

 set password for 'userone'@'%'=password('1234')

5. 为用户授权

授予userone管理newDB的全部权限 

  grant all privileges on dbdata.*@'%' to userone identified by '1234';

授予userone全部数据库权限,并修改密码

 grant all on *.* to 'usertwo'@'%' identified by '123456';





欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
原文地址:https://www.cnblogs.com/flyingcr/p/10326887.html