After installation is complete, the following error occurs when you log on MySQL:
Because the installation process did not allow to set a password, the password may be empty, but in any case have no access to MySQL.
So how to do it, then this solution will summarize the record it.
step 1:
Enter the following command terminal Ubuntu
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
Mysqld.cnf into the profile, and in this configuration file [mysqld] this was added a skip-grant-tables in this sentence.
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
skip-grant-tables
Role: that allows you to log into MySQL without a password.
Save: wq, quit.
Enter the following command:
Restart MySQL. As shown below:
Step 2:
Input terminal on Ubuntu
Met a password prompt directly enter, into the MySQL, respectively, perform the following three sentences:
The results as shown below:
Then enter quit, quit MySQL
Step 3:
Mysqld.cnf to re-enter the beginning of the file to add the skip-grant-tables to comment out this statement. As shown below:
And then return to the terminal input mysql -u root -p, you should be able to enter the database.
Step 4:
If at this time the error was reported as follows
Then you need to go back to step 3 in the revalidation commented that statement (that is, remove the # symbol), re-enter the mysql, first select a database (use mysql;), then enter the select user, plugin from user ;, look:
We can see from the figure in the implementation of a select user, plugin from user; later, the plugin root cause of the error is because the field is auth_socket, then we get rid of it for the following mysql_native_password on the line. Input:
And then enter the following, and then enter the select user, plugin from user; enter, we can see the root user to change field success. As shown below:
Finally quit exit. Return to Step 3.
Then the problem is completely resolved.
Expand Update:
In MySQL 8 version, the above statement updating the code appears to have changed, the syntax will be told is wrong, and here I have not posted about grammatical errors:
ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassward'; //newpassward 新密码
This phrase corresponds to the top of the second step can.
If you execute this statement appears The MySQL server is running with the --skip-grant-tables option so it can not execute this statemen this error, resolved as follows:
First flush privileges, and then perform the above statement to change the password.