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';
   
   





猜你喜欢

转载自blog.csdn.net/xiaoqiu_cr/article/details/80902792
今日推荐