https://downloads.mysql.com/archives/community/
下载地址:
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar
tar -xvf mysql-5.7.37-linux-glibc2.12-x86_64.tar
# 解压出来之后还有一个test的包,那个暂时先不管
tar -xvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/
cd /usr/local/
ln -sv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
添加PATH路径
# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
配置生效与检查
source /etc/profile
mysql --version
安装一些依赖包
yum -y remove mariadb*
yum -y install autoconf gcc glibc make openssl openssl-devel perl-JSON.noarch
添加mysql用户
useradd -M -s /sbin/nologin mysql
id mysql
创建数据目录
mkdir /home/my3306
chown -R mysql.mysql /home/my3306
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/home/my3306/ --explicit_defaults_for_timestamp
配置mysql服务,使用systemctl管理
vim /usr/lib/systemd/system/mysqld-3306.service
内容如下:
[Unit]
Description=MySQL Server 3306
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/mysql-3306.cnf
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
配置文件/etc/mysql-3306.cnf内容如下:
[mysqld]
innodb_buffer_pool_size = 5000M
server_id=15406
#log_slave_updates=1
port = 3306
datadir=/home/my3306
socket=/home/my3306/mysql.sock
log-error=/home/my3306/mysqld.log
pid-file=/home/my3306/mysqld.pid
log_bin=mysql-201-3306-binlog
# gtid最好是开启
gtid_mode=ON
enforce-gtid-consistency=ON
max_connections=2048
slow_query_log=ON
binlog_format=row
skip-name-resolve
log-slave-updates=1
relay_log_purge=0
back_log=128
wait_timeout=60
interactive_timeout=7200
key_buffer_size=16M
#query_cache_size=64M
#query_cache_type=1
#query_cache_limit=50M
max_connect_errors=20
sort_buffer_size=2M
max_allowed_packet=32M
join_buffer_size=2M
thread_cache_size=200
innodb_buffer_pool_size=1024M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_log_files_in_group=3
binlog_cache_size=2M
max_binlog_cache_size=8M
max_binlog_size=512M
expire_logs_days=7
read_buffer_size=2M
read_rnd_buffer_size=2M
使用systemctl管理服务
systemctl daemon-reload
systemctl enable mysqld-3306.service
systemctl start mysqld-3306.service
systemctl stop mysqld-3306.service
systemctl restart mysqld-3306.service
mysql服务启动后,登录,默认密码是初始化的时候生成的那个密码
mysql -uroot -S /home/my3306/mysql.sock -p
# 需要先修改root用户的默认密码才能执行后面的所有操作
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@1234';
新用户授权
use mysql;
create user user01@'10.1.0.%' identified by 'Root@1234';
grant all privileges on *.* to user01@'10.1.0.%' with grant option;
# 或者是
grant all privileges on *.* to 'user02'@'10.1.0.%' identified by 'Root@1234' with grant option;
grant all privileges on test.* to 'user03'@'10.1.0.%' identified by 'Root@1234' with grant option;
grant select on test.* to 'user04'@'10.1.0.%' identified by 'Root@1234' with grant option;
根据需要进行授权即可
注意:mysql 5.7默认的密码认证加密插件还是mysql_native_password。
使用二进制代码安装,相对于rpm包安装服务配置要麻烦一些,不过单机多实例配置也相对灵活。可以在一个主机上设置多个不同版本的mysql,只要在服务启动命令上做一些修改即可。