博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 用户管理
阅读量:7284 次
发布时间:2019-06-30

本文共 1701 字,大约阅读时间需要 5 分钟。

1.新建用户

mysql>create user 'root'@'localhost' identified by 'a123456';
mysql>insert into mysql.user(Host,User,Password) values("localhost","root",password("a123456"));
mysql>flush privileges;

在mysql5.6中127.0.0.1和localhost已经不再区分,记得以前版本,如果有root@127.0.0.1,但是没有root@localhost,使用127.0.0.1可以登录,但是使用localhost不能登录。

host 为 %,则表示可以远程登录,但是只有%本机是不可以登录的。

2.授权用户

mysql>grant all privileges on *.* to 'root'@'localhost' identified by 'a123456';
mysql>grant all on *.* to 'root'@'localhost' identified by 'a123456' with grant option;
mysql>flush privileges;

3.删除用户

mysql>delete from mysql.user where user='root' and host='locahost';
这个条语句不可以乱执行。

如果你真执行了,也没关系。后面会说解决办法。

4.修改用户密码

mysql>update mysql.user set password=password('654321a') where user='root' and host='localhost';
mysql>flush privileges;

5.修改用户

mysql>rename user 'test2'@'localhost' to 'test'@'%';

6.回收权限

mysql>revoke update on *.* from 'root'@'localhost';

 

继续说一下上面提到的问题:假如你忘记密码或者干脆把所有用户都删掉了

解决的办法就是 关闭mysql,重启。

在启动命令后面添加 --skip-grant-tables 选项。即不加载系统的权限表。

[root@localhost mysql]# bin/mysqld_safe --skip-grant-tables &

然后再添加用户,分配权限。

你可能遇到问题:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statementmysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

这时候你只需要 :flush privileges;

然后就可以正常操作了。

参考:

http://www.cnblogs.com/iosdev/archive/2013/07/15/3190431.html

with grant option与with admin option的区别:

http://blog.itpub.net/8570952/viewspace-198301/

关联连接:

http://blog.sina.com.cn/s/blog_51dea6c90100adcj.html

转载于:https://www.cnblogs.com/simpman/p/4193278.html

你可能感兴趣的文章
JS在textarea光标处插入文本
查看>>
c++ new的三种形态
查看>>
jsp文件做模板文件生成代码
查看>>
spring.net 学习笔记之 AOP (异常记录实例)转
查看>>
数据库模糊搜索时,关键字中有%号,怎么办?
查看>>
Android 内存溢出(Out Of Memory)的总结
查看>>
TextView不用获取焦点也能实现跑马灯
查看>>
Android HandlerThread简介
查看>>
win下 bundle install 显示json安装错误解决办法
查看>>
白话经典算法系列之五 归并排序的实现
查看>>
执行原因【菜鸟笔记】Ubuntu系统shellscript中 关于for循环以及declare出错的原因
查看>>
基于.net开发chrome核心浏览器【四】
查看>>
PHP header() 函数
查看>>
javascript构造函数与原型
查看>>
ActiveMQ应用笔记二:Producer与Consumer模板代码
查看>>
JavaFx初探
查看>>
Android创建启动画面
查看>>
微软职位内部推荐-SDE II
查看>>
laravel里面使用event
查看>>
Swift游戏实战-跑酷熊猫 06 创建平台类以及平台工厂类
查看>>