simpman

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 statement
mysql> 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

分类:

技术点:

相关文章: