Reference article: Ubuntu 18.04 version after installation Mysql, Mysql each time you visit need to add the issue of sudo
Sudo needs to solve problems connected msyql
Mysql version of this article 5.7.26-0ubuntu0.18.04.1
Step 1: Changing the root
View user's rights , whether it is mysql_native_password, if not, the auth_sock changed mysql_native_password.
update user set plugin = 'mysql_native_password' where user = 'root';
Or execute the following statement, so you do not need to perform content Step2 friends!
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
then
flush privilege;
Exit mysql.
Step2 modify or set the root password
After exiting the use mysql -u root -p found not to log Mysql, reported the mistake to:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
After the second article reference has been resolved.
First log in with debian-sys-maint, password file in /etc/mysql/debian.cnf
mysql -u debian-sys-maint -p
Then modify the root password (password can be the same as before):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Then, quit; quit.
After these two steps can then use mysql -u root -p login Mysql, you do not need to bring sudo.