美文网首页
MySQL相关操作

MySQL相关操作

作者: testerzhang | 来源:发表于2020-05-19 16:51 被阅读0次

    前言

    日常会需要使用MySQL,这里备忘下,后续持续更新。

    MySQL 5.7.28 创建用户并设置密码

    $ mysql -h127.0.0.1 -P3306 -uroot -p
    
    mysql> grant all privileges on testuser.* to testuser@'%' identified by 'testuser';
    ERROR 1290 (HY000): Unknown error 1290
    mysql> flush privileges;
    Query OK, 0 rows affected (0.07 sec)
    
    mysql> grant all privileges on testuser.* to testuser@'%' identified by 'testuser';
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    

    MySQL 8.0忘记密码后重置密码

    1. 修改配置文件my.cnf免密码登录

    在【mysqld】模块添加:skip-grant-tables 保存退出;

    1. 重启mysql服务

    2. 用root用户进行登录置空密码

    mysql> use mysql
    //将密码置空
    mysql> update user set authentication_string = '' where user = 'root';
    
    1. 去除免密码登录,并重启mysql服务
      注释掉步骤1的语句 # skip-grant-tables

    2. 用root用户进行空密码登录修改密码

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root密码';
    

    注意:root密码需要复杂点

    相关文章

      网友评论

          本文标题:MySQL相关操作

          本文链接:https://www.haomeiwen.com/subject/puibohtx.html