1. 程式人生 > >Linux MySQL-5.7 root初始密碼修改

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.   [[email protected] etc] # service mysql restart
  2.   Shutting down MySQL.. SUCCESS!
  3.   Starting MySQL. SUCCESS!
  4.   [[email protected] etc] #

 

登入上mysql,然後切換到mysql

 

  1.   [[email protected] 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.   [[email protected] etc]# /etc/init.d/mysql restart
  2.   Shutting down MySQL.. SUCCESS!
  3.   Starting MySQL. SUCCESS!
  4.   [[email protected] 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.  

    搞定!!