mysql create database, add users, user authorization (b)

First, create a mysql database

1. Create a database syntax

--创建名称为“testdb”数据库,并设定编码集为utf8
CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

Second, create a user

1. Create a new user

 --创建了一个名为:test 密码为:1234 的用户
 create user 'test'@'localhost' identified by '1234';

Note:
"localhost" here, means that the user can only log on locally, not remotely log in on another machine. If you want to remote login, it will "localhost" to "%", said can log on from any computer. You can also specify a machine can log in remotely.

2. Query User

--查询用户
select user,host from mysql.user;

3. Delete user

--删除用户“test”
drop user test@localhost ;
--若创建的用户允许任何电脑登陆,删除用户如下 drop user test@'%';

4. Change your password

--方法1,密码实时更新;修改用户“test”的密码为“1122”
set password for test =password('1122'); --方法2,需要刷新;修改用户“test”的密码为“1234” update mysql.user set password=password('1234') where user='test' --刷新 flush privileges;

5. assign permissions to users

--授予用户test通过外网IP对数据库“testdb”的全部权限
grant all privileges on 'testdb'.* to 'test'@'%' identified by '1234'; --刷新权限 flush privileges; --授予用户“test”通过外网IP对于该数据库“testdb”中表的创建、修改、删除权限,以及表数据的增删查改权限 grant create,alter,drop,select,insert,update,delete on testdb.* to test@'%'; 

6. View the user permissions

--查看用户“test”
show grants for test;
注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:flush privileges;



以上信息参考另一位博主的文章;有根据自己的理解加以补充:https://www.cnblogs.com/wuyunblog/p/9109269.html

Guess you like

Origin www.cnblogs.com/linuxtop/p/12216668.html