Introduction to MySQL (2)-Install MySQL database (version 8.0.25)

1. Update system software

sudo apt update

2. Installation

sudo apt install mysql-server  

3. Enter the database to set the password and permissions of the root account

sudo mysql 

4. Switch mysql database

use mysql;     

5. Modify the root user password

update user set plugin='mysql_native_password' where user='root';
alter user 'root'@'localhost' identified with mysql_native_password by '这里放你自己的密码'; 

6, open the database remote login

Enter one by one

flush privileges;
use mysql
select host,user from user;
update user set host='%' where user='root';
flush privileges;
use mysql
select host,user from user;

Even if the following picture appears

Insert picture description here

7. Refresh permissions


8. Exit the database


9. Open port 3306 of MySQL

Check if the port is open

netstat -an | grep 3306

If it is not turned on, do this: enter

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 

Modify the configuration file: put bind-address = line written off

This is it

Insert picture description here

10. Restart the database

sudo service mysql restart   

11. Log in

mysql -uroot -p                #方式一,正常登陆
mysql -hIP -P端口 -uroot -p    #方法二,可用于远程登录
Insert picture description here

12. Some other commands

Check mysql status: sudo service mysql status
start mysql service: sudo service mysql start
stop mysql service: sudo service mysql stop
restart mysql service:sudo service msyql restart

If you have the above content and a few references, you can almost succeed. Of course, I have installed it for a long time, because there are scattered other problems, such as different version instructions, software can’t be updated, etc. , So if there are questions in the middle, you can ask questions in the comment area. I saw that I could help as much as possible