下载安装包MySQL :: Download MySQL Community Server
解压安装包
tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
改名
mv mysql-5.7.39-linux-glibc2.12-x86_64 mysql5.7
在mysql5.7先创建 my.cnf 文件
[mysql]
# 默认字符集
default-character-set=utf8mb4
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
server-id = 3306
# user = mysql
socket = /tmp/mysql.sock
# 安装目录
basedir = /opt/mysql8
# 数据存放目录
datadir = /opt/mysql8/datas/mysql
log-bin = /opt/mysql8/datas/mysql/mysql-bin
innodb_data_home_dir =/opt/mysql8/datas/mysql
innodb_log_group_home_dir =/opt/mysql8/datas/mysql
#日志及进程数据的存放目录
log-error =/opt/mysql8/datas/mysql/mysql.log
pid-file =/opt/mysql8/datas/mysql/mysql.pid
# 服务端使用的字符集默认为8比特编码
character-set-server=utf8mb4
在mysql5.7下创建 datas 目录
初始化 datadir 目录
mysqld --defaults-file=/opt/mysql5.7/my.cnf --initialize-insecure
修改 mysql.server
vim /opt/mysql5.7/support-files/mysql.server
以上这几个变量按照自己的实际情况进行修改
启动mysql
mysqld --defaults-file=/opt/mysql5.7/my.cnf --user=root
修改权限
用客户端链接mysql服务
mysql -u root --skip-password
修改root密码为 123456
set password for root@localhost = password('123456');
开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;