mysql 权限


远程登录mysql

mysql -h ip -u root -p 密码

创建用户

格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
例1:增加一个test1用户,密码为123456,需要在mysql的root用户下进行

可以在任何主机上登录,并对所有数据库有查询,增加,修改和删除的功能。

grant select,insert,update,delete on *.* to test1@"%" identified by "123456";
flush privileges;

例2:增加一个test2用户,密码为123456,只能在192.168.2.12上登录,

并对数据库student有查询,增加,修改和删除的功能。需要在mysql的root用户下进行

grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by "123456";
flush privileges;

例3:授权用户test3拥有数据库student的所有权限

grant all privileges on student.* to test3@localhost identified by '123456';
flush privileges;

修改用户密码

update mysql.user set password=password('123456') where User='test1' and Host='localhost';
flush privileges;

删除用户

delete from user where user='test2' and host='localhost';
flush privileges;

删除数据库和删除表

drop database 数据库名;
drop table 表名;

删除账户及权限

drop user 用户名@'%'
drop user 用户名@localhost
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容