一、下载
MySQL下载官网:https://dev.mysql.com/downloads/mysql
根据目标主机的型号官网下载对应的mysql安装包,安装类型和名字如下:
mysql-server_5.7.31-1debian9_amd64.deb-bundle.tar
二、解压
tar -xvf mysql-server_5.7.31-1debian9_amd64.deb-bundle.tar
三、安装
根据需要安装必要的deb包,可以用dpkg --info 指定的包.deb查看依赖
1、先安装依赖
apt install libaio1 libnuma1 libmecab2 -y
2、然后依次按以下的顺序安装
(1)dpkg -i mysql-common_5.7.31-1debian9_amd64.deb
(2)dpkg -i mysql-community-client_5.7.31-1debian9_amd64.deb
(3)dpkg -i mysql-client_5.7.31-1debian9_amd64.deb
(4)dpkg -i mysql-community-server_5.7.31-1debian9_amd64.deb(注意:这一步,需要设置MySQL的root密码,步骤是第3步)
(5)dpkg -i mysql-server_5.7.31-1debian9_amd64.deb
3、设置密码
4、确认密码
四、配置
如果需要远程访问MySQL,修改配置,默认只能本地访问。
cd /etc/mysql/mysql.conf.d/
vim mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
bind-address = 127.0.0.1 # 修改为0.0.0.0即可
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 字符编码设置为utf8
character_set_server = utf8
init_connect = ‘SET NAMES utf8‘
1、重启
systemctl restart mysql
2、查看状态
systemctl status mysql
3、查看设置的字符集
mysql -u root -p
show variables like "%character%";show variables like "%collation%";
本文参考自:https://www.cnblogs.com/yoyotl/p/8057055.html