一、下载安装包
安装包下载 https://downloads.mysql.com/archives/community/
选择自己要下载的版本下载
二、上传到Linux机器进行解压
tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.39-linux-glibc2.12-x86_64 mysql-5.7.39
三、添加系统mysql组和MySQL用户
cat /etc/group | grep mysql
mysql:x:27:
cat /etc/passwd | grep mysql
mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin
如无,执行添加命令:
groupadd mysql
useradd -r -g mysql mysql
四、安装数据库
1.在解压的MySQL目录下创建data目录
2.将/usr/local/mysql/mysql-5.7的所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql/mysql-5.7
3.在/usr/local/mysql/mysql-5.7/support-files目录下创建my_default.cnf
cd support-files/
vim my_default.cnf
并且写入文件,保存覆盖
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql/mysql-5.7
datadir = /usr/local/mysql/mysql-5.7/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /usr/local/mysql/mysql-5.7/data/mysqld.log
pid-file = /usr/local/mysql/mysql-5.7/data/mysqld.pid
4.初始化 mysqld
cd /usr/local/mysql/mysql-5.7/
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7/ --datadir=/usr/local/mysql/mysql-5.7.39/data/
5.初始化成功,在日志中查看默认密码
cd /usr/local/mysql/mysql-5.7/data/
6.把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
7.登录mysql,修改密码,添加远程访问权限
见文章:
https://blog.51cto.com/u_15227402/5907011
8.重启mysql生效
service mysql stop 关闭mysql
service mysql start 开启mysql
service mysql restart 重启mysql