“FAQ:MySQL”的版本间差异

来自Wikioe
跳到导航 跳到搜索
(建立内容为“category:MySQL __TOC__ == MySQL8忘记并重置密码 == === 思路: === # 密码丢失,必须采用无密码启动的方式进入系统,才能进行…”的新页面)
 
第11行: 第11行:
=== 步骤: ===
=== 步骤: ===
# 修改配置文件<syntaxhighlight lang="shell" inline>vim /etc/my.cnf</syntaxhighlight>,添加<syntaxhighlight lang="shell" inline>skip-grant-table</syntaxhighlight>(跳过权限验证);
# 修改配置文件<syntaxhighlight lang="shell" inline>vim /etc/my.cnf</syntaxhighlight>,添加<syntaxhighlight lang="shell" inline>skip-grant-table</syntaxhighlight>(跳过权限验证);
#:
# 重启mysql服务:<syntaxhighlight lang="shell" inline>systemctl restart mysqld</syntaxhighlight>;
# 重启mysql服务:<syntaxhighlight lang="shell" inline>systemctl restart mysqld</syntaxhighlight>;
# mysql登录(无需密码):<syntaxhighlight lang="shell" inline>mysql -uroot -p</syntaxhighlight>;
# 刷新权限表:<syntaxhighlight lang="shell" inline>flush privileges;</syntaxhighlight>;
# 刷新权限表:<syntaxhighlight lang="shell" inline>flush privileges;</syntaxhighlight>;
# mysql登录(无需密码):<syntaxhighlight lang="shell" inline>mysql -uroot -p</syntaxhighlight>;
#:
# 重置密码:<syntaxhighlight lang="mysql">
# 重置密码:<syntaxhighlight lang="mysql">
use mysql;
use mysql;

2020年10月7日 (三) 01:26的版本


MySQL8忘记并重置密码

思路:

  1. 密码丢失,必须采用无密码启动的方式进入系统,才能进行修改密码操作;
  2. (Mysql5.7+)password字段和password()函数,密码为authentication_string字段;
  3. mysql8.0之前的版本加密规则是mysql_native_password,8.0之后是caching_sha2_password

步骤:

  1. 修改配置文件vim /etc/my.cnf,添加skip-grant-table(跳过权限验证);
  2. 重启mysql服务:systemctl restart mysqld
  3. mysql登录(无需密码):mysql -uroot -p
  4. 刷新权限表:flush privileges;
  5. 重置密码:
    use mysql;
    alter user 'root'@'localhost' identified by 'newpassword';
    
  6. 重置配置文件vim /etc/my.cnf,删除skip-grant-table
  7. 重启mysql服务:systemctl restart mysqld

其他:

  • Linux服务操作
    systemctl start mysqld		//开启服务
    systemctl stop mysqld 		//停止服务
    systemctl restart mysqld 	//重启服务
    systemctl status mysqld 	//服务状态查看
    
  • 查看用户相关信息:
    select host, user, authentication_string, plugin from user;
    
    1. host:用户登录方式,'localhost'本地登录,'%'可远程登录;
    2. authentication_string:用户密码;
    3. plugin:密码加密方式;
  • 命令行方式无密码启动MySQL(不修改配置文件):【???】
    1. 停止MySQL服务;
    2. 命令行启动Mysql:
      mysqld --console --skip-grant-tables --shared-memory
      
  • (进入mysql后)把 authentication_string 设置为空,所以可以免密码登录【???】:
    use mysql;
    update user set authentication_string='' where user='root';
    
  • 查看MySQL密码校验相关设置:
    SHOW VARIABLES LIKE 'validate_password.%';
    
  • 修改密码策略:
    set global validate_password.length = 6;		//密码长度
    
    set global validate_password.policy = 'LOW';	//密码策略级别
    
    FLUSH PRIVILEGES;								//刷新权限