Setting root password in fresh mysql 5.7 installation
If you just run mysql command under root user you will be granted access without asked for password, because socket authentication enabled for root@localhost.
This guide is misleading.
The only way to set password is to switch to native authentication like:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
In my insane research for a solution I took a look to /var/log/mysqld.log
and found this line:
[Note] A temporary password is generated for root@localhost: abc123
Looks like mysql 5.7+ generates a random password in the installation and prompted in that file.
Use the below steps to reset the password:
$ sudo systemctl start mysqld
Reset the MySQL server root password.
$sudo grep 'temporary password' /var/log/mysqld.log
Output something like:
10.744785Z 1 [Note] A temporary password is generated for root@localhost: o!5y,oJGALQa
Use the above password during reset mysql_secure_installation process.
$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
You have successfully reset the root password of MySQL server. Use the below command to check the MySQL server connecting or not.
$ mysql -u root -p
See my article: Install Latest MySQL 5.7 on RHEL/Centos 7