Install mysql on Ubuntu:
sudo apt-get update
sudo apt-get install mysql-server
Encountered an error when logging in:
mysql -u root -p
Solution:
Enter sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
into the mysql configuration file:
Add skip-grant-tables after skip-external-locking, save and exit.
终端执行 service mysql restart
, Restart mysql.
终端执行mysql -u root -p
, Prompt to enter the password and press Enter. After entering mysql, execute the following three sentences:
use mysql;
update user set authentication_string=PASSWORD('新密码') where user='root';
flush privileges;
Then enter quit
and exit mysql.
Re-enter the mysqld.cnf file and sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf,
comment out the skip-grant-tables statement added at the beginning.
Then return to the terminal mysql -u root -p
and enter the password you just set.