1.建立用户mysql
#test表示你要创建的用户名,后面的123456表示密码, sql
#localhost限制在固定地址localhost登录 数据库
CREATE USER test@localhost IDENTIFIED BY '123456';ide
2.受权用户test
受权格式:grant 权限 on 数据库.* to 用户名@登陆主机 identified by "密码"; 登录
2.1 登陆MYSQL(有ROOT权限),这里以ROOT身份登陆:date
@>mysql -u root -pselect
@>密码权限
2.2 首先为用户建立一个数据库(testDB):密码
mysql>create database testDB;
2.3 受权test用户拥有testDB数据库的全部权限(某个数据库的全部权限):
mysql>grant all privileges on testDB.* to test@localhost identified by '123456';
mysql>flush privileges;//刷新系统权限表
格式:grant 权限 on 数据库.* to 用户名@登陆主机 identified by "密码";
2.4 若是想指定部分权限给一用户,能够这样来写:
mysql>grant select,update on testDB.* to test@localhost identified by '123456';
mysql>flush privileges; //刷新系统权限表
2.5 受权test用户拥有全部数据库的某些权限:
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "123456";
//test用户对全部数据库都有select,delete,update,create,drop 权限。
//@"%" 表示对全部非本地主机受权,不包括localhost。(localhost地址设为127.0.0.1,若是设为真实的本地地址,不知道是否能够,没有验证。)
//对localhost受权:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';便可。
3. 删除用户
@>mysql -u root -p
@>密码
mysql>Delete FROM user Where User='test' and Host='localhost';
mysql>flush privileges;
mysql>drop database testDB; //删除用户的数据库
删除帐户及权限:>drop user 用户名@'%';
>drop user 用户名@ localhost;
4. 修改指定用户密码
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password('新密码') where User="test" and Host="localhost";
mysql>flush privileges;