Linux MySQL-5.7 root初始密碼修改
阿新 • • 發佈:2018-11-07
- A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
- You will find that password in '/root/.mysql_secret'.
- You must change that password on your first connect,
- no other statement but 'SET PASSWORD' will be accepted.
-
See the
manual for the semantics of the 'password expired' flag.
- Also, the account for the anonymous user has been removed.
-
In addition, you can run:
但是坑爹的是壓根沒在/root下找到.mysql_secret檔案,好把,百度,使用無需驗證的方式,修改my.cnf
- [mysqld]
- port=3306
- character- set-server = utf8
- explicit_defaults_for_timestamp= 1
- skip-grant-tables=1
重啟mysql
- [[email protected] etc] # service mysql restart
- Shutting down MySQL.. SUCCESS!
- Starting MySQL. SUCCESS!
- [[email protected] etc] #
登入上mysql,然後切換到mysql
- [[email protected] etc]# mysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1
- Server version: 5.7.3-m13 MySQL Community Server (GPL)
- Copyright (c) 2000, 2013, 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> 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
接下來就是重點了修改密碼,需要修改兩次,一次authentication_string,一次 password
- mysql> UPDATE user SET authentication_string=PASSWORD( "123456") WHERE user='root';
- Query OK, 4 rows affected (0.00 sec)
- Rows matched: 4 Changed: 4 Warnings: 0 mysql>
- update user set password=password('123456') where user='root';
- Query OK, 4 rows affected (0.00 sec)
- Rows matched: 4 Changed: 4 Warnings: 0
然後把之前的配置skip-grant-tables=1去掉,重新啟動mysql
- [[email protected] etc]# /etc/init.d/mysql restart
- Shutting down MySQL.. SUCCESS!
- Starting MySQL. SUCCESS!
- [[email protected] etc]# mysql -proot -p
- mysql: [Warning] Using a password on the command line interface can be insecure.
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1
- Server version: 5.7.3-m13
- Copyright (c) 2000, 2013, 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>
最後還是要再執行下修改密碼的語句的
- mysql> use mysql
- ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
- mysql> SET PASSWORD = PASSWORD( '123456');
- Query OK, 0 rows affected (0.00 sec)
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | test |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql>
-
搞定!!