zoukankan      html  css  js  c++  java
  • MySQL修改密码

    一、查看MySQL临时密码

    Linux安装好MySQL后,为了增加数据库的安全性,在安装时会为root用户生成一个临时的随机密码,存放在/var/log/mysqld.log 中。

    [root@localhost mysql_bundle]# cat /var/log/mysqld.log | grep temp
    2020-05-12T12:05:15.901037Z 1 [Note] A temporary password is generated for root@localhost: .fJJk*j&t4h6
    2020-05-12T12:05:18.403371Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
    

    这个.fJJk*j&t4h6就是临时密码。第一次登录就使用这个密码。

    二、修改密码

    登录后输入show databases命令查看数据库中有哪些库,发现出现错误。

    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> 
    

    这条错误语句时说必须使用ALTER USER重设密码才可以执行这条语句。
    那么接下来就重置密码吧。
    注意:密码要符合复杂度规则,也就是说要包含大小写字母、数字、特殊符号,并且长度不小于八位。否则会报错,如下:

    mysql> alter user root@localhost identified by '123456';
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    mysql> 
    

    设置一个合格的密码。

    mysql> alter user root@localhost identified by 'MySQLroot123#';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> 
    
    • alter user是命令
    • root@localhost 是用户名,这是MySQL用户名的完整格式,@符号前面是用于登录的用户名,后面的是主机名,localhost表示root只能在本地登录。
    • identified by是指定密码的命令
      使用exit退出系统,之后就可以使用新密码登录MySQL。
    [root@localhost mysql_bundle]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 5
    Server version: 5.7.29 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> exit
    Bye
    [root@localhost mysql_bundle]# 
    
  • 相关阅读:
    apk应用签名获取
    git强制推送命令
    Maven 将本地jar包添加到本地仓库
    关于Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin的解决方案
    启动React-Native项目步骤
    Git初始化本地项目并提交远程仓库基础操作
    You have not accepted the license agreements of the following SDK components: [Android SDK Build-Tools 26.0.1, Android SDK Platform 26]
    kenkins安装
    Linux关闭防火墙和SELinux
    Linux下nginx安装配置
  • 原文地址:https://www.cnblogs.com/CharrammaBlog/p/12878503.html
Copyright © 2011-2022 走看看