首页 > 代码库 > MySQL简单的用户管理

MySQL简单的用户管理

mysql安装后的一点安全策略就是删除空用户和host不为localhost的用户

1、删除空用户

删除空用户

mysql> select mysql.user,host,password from user whereuser=‘‘;    查询用户

mysql> delete from user where user=‘‘;        #删除user=空的用户

删除host不等于localhost的用户

mysql> select user,host,password from user where host!=‘localhost‘;

mysql>delete from user where host!=’localhost’;

2、为用户设置密码

mysql> update user set password=password(123456);

mysql>flush privileges;

创建mysql用户及赋予用户权限

1.创建用户并设置密码

mysql>create user acbuf@’localhost’ identified by‘123456’;

mysql>create user acbuf@’localhost’;

 

2.常用的创建用户方法;创建用户的同时并进行授权 grant

mysql> grant all on blog.* to ‘acbuf‘@‘localhost‘ identified by ‘123456‘; #不会自动创建blog

 

3.为已有用户授权库。

mysql> grant all on blog.* to acbuf@‘localhost‘;

 

4.查看用户权限

mysql>show grants for acbuf@’localhost’;

 

5.root密码忘记重新设置密码

1.编辑/etc/my.cnf[mysqld]段中添加skip-grant-tables,然后重启mysqld

然后mysql进入即可,然后update为root设置密码

,设置完成后把添加的skip-grant-tables删除重启即可。

2.[root@test /]# mysqld_safe--skip-grant-tables --user=mysql  &

后续步骤跟第一个方法一样。

本文出自 “董书豪” 博客,请务必保留此出处http://dongshuhao.blog.51cto.com/13042423/1945965

MySQL简单的用户管理