1, solution a: change table method

    ~ use mysql;
    ~ update user set host = The '%' where user = 'root'; ~ select host, user from user; ~ flush privileges; // Refresh permissionsCopy the code

2. Method two: Authorization method

GRANT ALL PRIVILEGES ON *.* TO'root'@The '%' IDENTIFIED BY 'Your password'WITH GRANT OPTION; flush privileges; GRANT ALL PRIVILEGES ON *.* TO'root'@'192.168.1.2 instead IDENTIFIED BY 'password' WITH GRANT OPTION;
    flush privileges;
Copy the code

3 MySQL Error: : ‘Access denied for user ‘root’@’localhost’

Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
Add skip-grant-tables under [mysqld]
Restart Mysql
You should be able to login to mysql now using the below command mysql -u root -p
Run mysql> flush privileges;
Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
Go back to /etc/my.cnf and remove/comment skip-grant-tables
Restart Mysql
Now you will be able to login with the new password mysql -u root -p
Copy the code

4 set sql_mode

# 1
top@ubuntu:/etc/mysql$ sudo vim mysql.conf.d/mysqld.cnf

#2 add sql_mode= to mysqld
[mysqld]
#sql_mode
sql_mode =

# 3
top@ubuntu:/etc/mysql$ sudo service mysql restart
Copy the code