MysqL 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail
@H_301_3@-- 512.笔记 jb51.cc MysqL -u root -p password use MysqL; insert into user(host,user,password) values('localhost','hail',password('hail')); flush privileges; create database haildb; grant all privileges on haildb.* to hail@localhost identified by 'hail'; flush privileges;
如果想指定部分权限给用户
@H_301_3@-- 512.笔记 jb51.cc grant select,update on haildb.* to hail@localhost identified by 'hail'; flush privileges;
@H_301_3@-- 512.笔记 jb51.cc delete from user where user='hail' and host='localhost'; flush privileges;
@H_301_3@-- 512.笔记 jb51.cc drop database haildb;
@H_301_3@-- 512.笔记 jb51.cc update user set password=password('new_password') where user='hail' and host='localhost'; flush privileges;
@H_301_3@-- 512.笔记 jb51.cc MysqL -h ip -u root -p 密码
2.创建用户
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
例1:增加一个test1用户,密码为123456,可以在任何主机上登录,并对所有数据库有查询,增加,修改和删除的功能。需要在MysqL的root用户下进行
@H_301_3@-- 512.笔记 jb51.cc MysqL>grant select,insert,update,delete on *.* to test1@"%" identified by "123456"; MysqL>flush privileges;
例2:增加一个test2用户,密码为123456,只能在192.168.2.12上登录,并对数据库student有查询,增加,修改和删除的功能。需要在MysqL的root用户下进行
@H_301_3@-- 512.笔记 jb51.cc MysqL>grant select,delete on student.* to test2@192.168.2.12 identified by "123456"; MysqL>flush privileges;
@H_301_3@-- 512.笔记 jb51.cc MysqL>grant all privileges on student.* to test3@localhost identified by "123456"; MysqL>flush privileges;
@H_301_3@-- 512.笔记 jb51.cc MysqL>update MysqL.user set password=password("123456") where User="test1" and Host="localhost"; MysqL>flush privileges;
@H_301_3@-- 512.笔记 jb51.cc MysqL>delete from user where user="test2" and host="localhost"; MysqL>flush privileges;
@H_301_3@-- 512.笔记 jb51.cc MysqL>drop database 数据库名; MysqL>drop table 表名;
6.删除账户及权限
@H_301_3@-- 512.笔记 jb51.cc drop user 用户名@"%" drop user 用户名@localhost flush privileges;