The problem and solution of no prompt for password when installing MySQL in Ubuntu 18.04

Time:2021-6-11

The installation of MySQL 5.7 in Ubuntu 1804 is very detailed.

Execute command to install MySQL


sudo apt install mysql-server
sudo apt install mysql-client

After installation, check whether it starts


sudo ps aux | grep mysql

If it has been started, you can see the corresponding information after executing the above command. If it has not been started, you can execute the following command to start MySQL:


sudo service mysql start

In addition, the command to restart and close MySQL will be used later


sudo service mysql restart
sudo service mysql stop

After ensuring that MySQL is successfully started, you can log in to MySQL, but there is no prompt to enter the user name and password in the installation process. At this time, you can view the default user name and password in ‘/ etc / MySQL / Debian. CNF’:


sudo cat /etc/mysql/debian.cnf

在这里插入图片描述

Use user and password to log in to MySQL:


mysql -udebian-sys-maint -pZBms1EM5icCfeePV

在这里插入图片描述

But the default user name and password are hard to remember. You can add a new one named my through the following SQL statement_ Name, password is my_ Password user:


show databases;
use mysql;
update user set authentication_string=PASSWORD("my_password") where user='my_name';
update user set plugin="mysql_native_password";
flush privileges;
exit;

在这里插入图片描述

After adding users, restart MySQL and use my_ Name login.

summary

The above is Xiaobian’s introduction to the problem and solution of no password prompt when installing MySQL in Ubuntu 18.04. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!