Do not know which version to start with on Ubuntu apt After installing MySQL, you will not be prompted to set the password.
Installation MySQL5.7
sudo apt install mysql-server -y
Then find the MySQL configuration file directory
sudo cat /etc/mysql/debian.cnf
You will see the default MySQL account debian-sys-maint and default random password
mysql -u debian-sys-maint -p
You will be prompted to enter a password! Enter the password to see it go into the inside of MySQL cli
Then modify the MySQL password authentication plug-in
MySQL5.6 With the addition of a password authentication plug-in, MySQL5.7 default root password authentication plug-in installed on Ubuntu is auth_socket, we need to plug changed mysql_native_password
update user set plugin = 'mysql_native_password' where user ='root';
Then change the root account password
update user set authentication_string=password('你的密码') where user='root';
Then refresh MySQL
flush privileges;
Then quit MySQL, log back in using the modified password.