安装包下载 https://downloads.mysql.com/archives/community/
选择自己要下载的版本下载
tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gzmv mysql-5.7.39-linux-glibc2.12-x86_64 mysql-5.7.39
cat /etc/group | grep mysqlmysql:x:27:cat /etc/passwd | grep mysqlmysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin如无,执行添加命令:groupadd mysqluseradd -r -g mysql mysql
1.在解压的MySQL目录下创建data目录
(资料图)
mkdir 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_TABLESbasedir = /usr/local/mysql/mysql-5.7datadir = /usr/local/mysql/mysql-5.7/dataport = 3306socket = /tmp/mysql.sockcharacter-set-server=utf8log-error = /usr/local/mysql/mysql-5.7/data/mysqld.logpid-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