美文网首页
Ubuntu上MySQL未设置密码或者忘记密码解决办法

Ubuntu上MySQL未设置密码或者忘记密码解决办法

作者: 沉思的雨季 | 来源:发表于2020-07-03 15:01 被阅读0次

    1、查看内置维护账户及密码

    
    hadoop@master:/etc/mysql$ sudo cat /etc/mysql/debian.cnf
    # Automatically generated for Debian scripts. DO NOT TOUCH!
    [client]
    host     = localhost
    user     = debian-sys-maint
    password = K6Ob75iKnrTAarer
    socket   = /var/run/mysqld/mysqld.sock
    [mysql_upgrade]
    host     = localhost
    user     = debian-sys-maint
    password = K6Ob75iKnrTAarer
    socket   = /var/run/mysqld/mysqld.sock
    basedir  = /usr
    

    注:user值为账户名,password值为密码。

    2、使用内置维护账户信息登录

    hadoop@master:/etc/mysql$ mysql -u debian-sys-maint -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 37
    Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2018, 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | hive               |
    | hue                |
    | mysql              |
    | performance_schema |
    +--------------------+
    5 rows in set (0.11 sec)
    

    3. 使用MySQL内置数据库,修改root登录密码

    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> update mysql.user set authentication_string=password('root') where user='root';
    Query OK, 1 row affected, 1 warning (0,00 sec)
    Rows matched: 1  Changed: 1  Warnings: 1
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0,00 sec)
    
    mysql> exit
    Bye
    

    4、重启MySQL数据库服务,使用root密码登录

    hadoop@master:/etc/mysql$ sudo /etc/init.d/mysql restart
     * Stopping MySQL database server mysqld                                                                                                                            [ OK ] 
     * Starting MySQL database server mysqld                                                                                                                            [ OK ] 
     * Checking for tables which need an upgrade, are corrupt or were 
    not closed cleanly.
    hadoop@master:/etc/mysql$ mysql -u root -p            
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 38
    Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2018, 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>
    

    相关文章

      网友评论

          本文标题:Ubuntu上MySQL未设置密码或者忘记密码解决办法

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