51qsx 发表于 2018-10-8 11:27:20

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’>  mysql>create user acbuf@’localhost’;
  2.常用的创建用户方法;创建用户的同时并进行授权 grant
  mysql> grant all on blog.* to 'acbuf'@'localhost'>不会自动创建blog库
  3.为已有用户授权库。
  mysql> grant all on blog.* to acbuf@'localhost';
  4.查看用户权限
  mysql>show grants for acbuf@’localhost’;
  5.root密码忘记重新设置密码
  1.编辑/etc/my.cnf在段中添加skip-grant-tables,然后重启mysqld。
  然后mysql进入即可,然后update为root设置密码
  ,设置完成后把添加的skip-grant-tables删除重启即可。
  2.# mysqld_safe--skip-grant-tables --user=mysql&
  后续步骤跟第一个方法一样。

页: [1]
查看完整版本: MySQL简单的用户管理