mysql的用户管理

1,mysql重置root密码。

  • 编辑配置文件 /etc/my.cnf ,在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证

  • 接下来我们需要重启MySQL,使用service mysqld restart

  • 进入mysql中重置密码,

    mysql> update user set password="你的新密码" where user="root";
    mysql> flush privileges;
    mysql> quit
  • 退出,注释掉配置文件新增的那行,重启。再登录。

 

2,mysql设置其它主机远程登录相关。

使用root用户登录mysql客户端,进入mysql库里面

1,设置访问单个数据库权限
mysql>grant all privileges on test.* to 'root'@'%';
说明:设置用户名为root,密码为空,所有主机可访问数据库test,'%'表示所有主机

2,设置访问全部数据库权限
mysql>grant all privileges on *.* to 'root'@'%';
说明:设置用户名为root,密码为空,所有主机可访问所有数据库*

3,设置指定用户名访问权限
mysql>grant all privileges on *.* to 'liuhui'@'%';
说明:设置指定用户名为liuhui,密码为空,可访问所有数据库*

4,设置密码访问权限
mysql>grant all privileges on *.* to 'liuhui'@'%' IDENTIFIED BY 'liuhui';
说明:设置指定用户名为liuhui,密码为liuhui,可访问所有数据库*

5,设置指定可访问主机权限
mysql>grant all privileges on *.* to 'liuhui'@'10.2.1.11';

6,删除权限
mysql>revoke all privileges on *.* from 'liuhui'@'10.2.1.11';

 

3,mysql 的用户管理。 使用root登录后,在mysql.user 表里,可以select host,user,password 等信息。

mysql5.7以前使用下面的语句查询
mysql> select user,host,password from mysql.user;

mysql5.7以后
mysql> select user,host,authentication_string from mysql.user;

也是在这里配置远程登录主机。host='%'表示任意主机远程登录。user 列为空,表示任意用户 都可以登录。可以删除,创建,修改用户。(create、alter、drop)

修改mysql的用户密码,分别使用grant、alter、set修改
①mysql> grant all on *.* to '用户名'@'登录主机' identified by '密码';
​
②mysql> alter user '用户名'@'登录主机' identified by '密码(自定义)';
#这个在5.7以上使用,并且要查看 plugin 的类型,在带上参数
​
③mysql> SET PASSWORD FOR '用户名'@'登录主机' = PASSWORD('密码');
eg:set password for root@192.168.1.101 = password('123456');
​
③mysql> update mysql.user set password=password('123456') where user='root' and host='localhost';
​
tips:
密码必须是被加密的,客户端才能正常登录。
一般使用update语句修改的密码都没有加密的原因,是因为没有用 password() 这个函数吧。使用这个函数也可以修改成功密码。
建议修改后去看下密码。
​
数据库名是 反引号 (`dadabase`)
tips:
密码必须是被加密的,客户端才能正常登录。
一般使用update语句修改的密码都没有加密的原因,是因为没有用 password() 这个函数吧。使用这个函数也可以修改成功密码。
建议修改后去看下密码。

数据库名是 反引号 (`dadabase`)

 4,mysql设置简单密码

mysql5.7上可以设置不符合要求的简单的密码,首先跳过了登录验证,然后进去修改root的密码,再没有说密码不符合要求的报错提示了

mysql5.7以上的版本里,password字段都替换成了authentication_string

原文地址:https://www.cnblogs.com/fengfengyang/p/14598814.html