1. Install MySQL 5.7
1. Replace the image source
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old #备份原来的文件
sudo vim /etc/apt/sources.list #修改sources.list文件
The content of the configuration file is as follows:
# 清华镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
2. update
sudo apt update # 更新镜像源
3. Install MySQL5.7
sudo apt install -y mysql-server-5.7
(Need to enter the password of the root user of mysql twice
软件包设置
┌──────────────────────────┤ 正在设定 mysql-server-5.7 ├──────────────────────────┐
│ While not mandatory, it is highly recommended that you set a password for the │
│ MySQL administrative "root" user. │
│ │
│ If this field is left blank, the password will not be changed. │
│ │
│ New password for the MySQL "root" user: │
│ │
│ *********______________________________________________________________________ │
│ │
│ <确定> │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘
软件包设置
┌────────┤ 正在设定 mysql-server-5.7 ├────────┐
│ │
│ │
│ Repeat password for the MySQL "root" user: │
│ │
│ *********__________________________________ │
│ │
│ <确定> │
│ │
└─────────────────────────────────────────────┘
4. After the installation is complete, check the version of MySQL
mysql -V # 查看mysql版本
5. Connect to MySQL (use root and the root password you just set)
➜ ~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.33-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2. Configure remote connection
1. Modify the configuration file
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
Find the bind-address and modify the value to 0.0.0.0
Insert the picture description here
Restart MySQL
sudo /etc/init.d/mysql restart
2. Authorize remote connection services for users
Log in to the MySQL database as the root user
mysql -u root -p
Use the MySQL command to authorize the MySQL remote connection service for the root user
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Write the configuration into the MySQL grant table
flush privileges;
Then you can connect to the remote connection
3. Start and stop services
#启动
sudo service mysql start
#停止
sudo service mysql stop