Setting root password in fresh mysql 5.7 installation I am trying to install mysql in a serving having CentOS Linux release 7.2.1511. Take a look to the process installation:

# sudo yum install mysql-server


Output:

Dependencies Resolved

===========================================================================================================================================================================================================
 Package                                                 Arch                                    Version                                         Repository                                           Size
===========================================================================================================================================================================================================
Removing:
 mysql-community-client                                  x86_64                                  5.7.10-1.el7                                    @mysql57-community                                  109 M
 mysql-community-server                                  x86_64                                  5.7.10-1.el7                                    @mysql57-community                                  652 M

Transaction Summary
===========================================================================================================================================================================================================


I ran the mysql damon:

# sudo service mysqld start


Checking the service:

# ps -ef|grep mysql
mysql     1371     1  0 22:17 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid


Here comes the problem driving me crazy. I want to set root password for the very first time, so I did:

# sudo mysql_secure_installation
// when password is required, I just type "enter key"


But the output: Securing the MySQL server deployment.


  Enter password for user root:  Error: Access denied for user
  'root'@'localhost' (using password: NO)


Googling the error, in 90% of cases, the solution is to call mysqld_safe --skip-grant-tables &amp; command:

service mysqld stop
mysqld_safe --skip-grant-tables &amp;
mysql --user=root mysql
update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;


But mysqld_safe prompts an "command not found" error. I also tested with sudo mysqld --skip-grant-tables &amp;, but it does not do anything. I will appreciate if you guide me to the right direction in order to set root password. Thank you in advance.
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';