Linux MySQL-5.7 root初始密码修改

 

  1.  
    A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
  2.  
    You will find that password in '/root/.mysql_secret'.
  3.  
     
  4.  
    You must change that password on your first connect,
  5.  
    no other statement but 'SET PASSWORD' will be accepted.
  6.  
    See the manual for the semantics of the 'password expired' flag.
  7.  
     
  8.  
    Also, the account for the anonymous user has been removed.
  9.  
     
  10.  
    In addition, you can run:

但是坑爹的是压根没在/root下找到.mysql_secret文件,好把,百度,使用无需验证的方式,修改my.cnf
  1.  
    [mysqld]
  2.  
    port=3306
  3.  
    character- set-server = utf8
  4.  
    explicit_defaults_for_timestamp= 1
  5.  
    skip-grant-tables=1
就是这句,停止权限验证skip-grant-tables=1

重启mysql

  1.  
    [root@cdh etc] # service mysql restart
  2.  
    Shutting down MySQL.. SUCCESS!
  3.  
    Starting MySQL. SUCCESS!
  4.  
    [root@cdh etc] #

登录上mysql,然后切换到mysql

  1.  
    [root@cdh etc]# mysql
  2.  
    Welcome to the MySQL monitor. Commands end with ; or \g.
  3.  
    Your MySQL connection id is 1
  4.  
    Server version: 5.7.3-m13 MySQL Community Server (GPL)
  5.  
     
  6.  
    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7.  
     
  8.  
    Oracle is a registered trademark of Oracle Corporation and/or its
  9.  
    affiliates. Other names may be trademarks of their respective
  10.  
    owners.
  11.  
     
  12.  
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13.  
     
  14.  
    mysql> use mysql
  15.  
    Reading table information for completion of table and column names
  16.  
    You can turn off this feature to get a quicker startup with -A
  17.  
     
  18.  
    Database changed

接下来就是重点了修改密码,需要修改两次,一次authentication_string,一次 password

  1.  
    mysql> UPDATE user SET authentication_string=PASSWORD( "123456") WHERE user='root';
  2.  
    Query OK, 4 rows affected (0.00 sec)
  3.  
    Rows matched: 4 Changed: 4 Warnings: 0 mysql>
  4.  
    update user set password=password('123456') where user='root';
  5.  
    Query OK, 4 rows affected (0.00 sec)
  6.  
    Rows matched: 4 Changed: 4 Warnings: 0

然后把之前的配置skip-grant-tables=1去掉,重新启动mysql

  1.  
    [root@cdh etc]# /etc/init.d/mysql restart
  2.  
    Shutting down MySQL.. SUCCESS!
  3.  
    Starting MySQL. SUCCESS!
  4.  
    [root@cdh etc]# mysql -proot -p
  5.  
    mysql: [Warning] Using a password on the command line interface can be insecure.
  6.  
    Enter password:
  7.  
    Welcome to the MySQL monitor. Commands end with ; or \g.
  8.  
    Your MySQL connection id is 1
  9.  
    Server version: 5.7.3-m13
  10.  
     
  11.  
    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  12.  
     
  13.  
    Oracle is a registered trademark of Oracle Corporation and/or its
  14.  
    affiliates. Other names may be trademarks of their respective
  15.  
    owners.
  16.  
     
  17.  
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  18.  
     
  19.  
    mysql>

最后还是要再执行下修改密码的语句的

  1.  
    mysql> use mysql
  2.  
    ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
  3.  
    mysql> SET PASSWORD = PASSWORD( '123456');
  4.  
    Query OK, 0 rows affected (0.00 sec)
  5.  
     
  6.  
    mysql> show databases;
  7.  
    +--------------------+
  8.  
    | Database |
  9.  
    +--------------------+
  10.  
    | information_schema |
  11.  
    | mysql |
  12.  
    | performance_schema |
  13.  
    | test |
  14.  
    +--------------------+
  15.  
    4 rows in set (0.00 sec)
  16.  
     
  17.  
    mysql>
  18. 搞定!!

猜你喜欢

转载自www.cnblogs.com/dwdw/p/9921098.html