I\'m setting up a new server and keep running into this problem.
When I try to login to the MySQL database with the root user, I get the error:
I also faced the same issue at the first time.
Now it is fixed:
First, you copy the /etc/mysql/mysql.conf.d/mysqld.cnf
file and past in to /etc/mysql/my.cnf
.
You can do it by command:
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf
Now let's Rest the password:
Use the following commands in your terminal:
sudo service mysql stop
sudo service mysql start
sudo mysql -u root
Now you are inside the mysql console.
Then let's write some queries to reset our root password
USE mysql
update mysql.user set authentication_string=password('newpass') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit
Now we can clean /etc/mysql/my.cng
Open the above file in your editor and remove the whole lines inside the file.
After that let's restart mysql:
sudo mysql service restart
Now let's use mysql with newly created password:
sudo mysql -u root -p
Finally enter your newly created password.