One of the main aspects of mysql5.7 's new features is a great increase in security, which, by default, creates a random password for the [email protected] user after installing MySQL, a random password that needs to be found in different ways on different systems. Otherwise, you cannot log in to MySQL and modify the initial password.
The following is a CentOS 7 example of how to find the initial random password.
On a version less than MySQL 5.7.6, MySQL initializes the database with the mysql_install_db command, which creates a. mysql_secret file in the root directory of the user who installed MySQL, which records the random password generated by the initialization. Users can log in to MySQL with a password and re-modify the password.
For the later 5.7 series versions of MySQL 5.7.6, MySQL initializes the database with the mysqld--initialize or mysqld--initialize-insecure command, which can not generate random passwords. However, when installing MySQL, the default is to use the previous command, which also generates a random password. The password is saved in the MySQL log file.
After installing MySQL using the rpm command on the CentOS 7 system, the MySQL configuration file is/etc/my.cnf, open the file, you can see the configuration information of MySQL DataDir and log files, and the following:
Datadir=/var/lib/mysql
Log-error=/var/log/mysqld.log
Open the/var/log/mysqld.log file, search string a temporary password is generated for [email protected]:, you can find this random password, usually this line of logs in the first few lines of the log file, more easily seen.
Log in to MySQL with the random password you found, and after the first login, MySQL will not be able to perform any other database operations than it has to modify the default password, which reflects the ever-increasing MySQL security.
Problems with initial root password not found after initial installation of Mysql5.7 or above version