Linux环境下Mysql多版本部署

  安装环境:OS:Centos 7.9

                     已经安装的Mysql:Mysql 8.0.26    安装目录:/usr/local/mysql

  需要安装的Mysql版本:Mysql 5.7.35

  多版本安装思路:Mysql安装目录、数据文件目录、pid文件、socket文件,监听端口,配置文件等都设置不同的位置。

  1.安装过程:

  先前的安装,已经建立了OS用户和环境变量,本次安装就可以略过这些步骤。

  1.1 解压安装包

cd /usr/local
tar zxvf mysql-5.7.35-el7-x86_64.tar.gz -C /usr/local/
mv mysql-5.7.35-el7-x86_64 mysql-5.7.35

cd /usr/local/mysql-5.7.35
mkdir mysql-files run log
touch log/mysqld.log
chown -R mysql:mysql /usr/local/mysql /usr/local/mysql-5.7.35 /data/mysql5.7
chmod 750 mysql-files

1.2 建Mysql配置文件

vi /usr/local/mysql-5.7.35/my.cnf
[client]
port = 3307
default-character-set=utf8

[mysqld]
default-storage-engine=innodb
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=1                                
max_allowed_packet=16M
character_set_server=utf8
port = 3307
max_connections=2000

init_connect='SET NAMES utf8'

basedir=/usr/local/mysql-5.7.35
datadir=/data/mysql5.7
socket=/usr/local/mysql-5.7.35/mysql.sock
log-error=/usr/local/mysql-5.7.35/log/mysqld.log
pid-file=/usr/local/mysql-5.7.35/run/mysqld.pid

#bin log
server_id=101
log-bin=/usr/local/mysql-5.7.35/log/product-bin

slave-skip-errors=all
skip-slave-start=1

relay_log=mysql-relay-bin
expire_logs_days=10

#slow query log
slow_query_log=1
slow_query_log_file=/usr/local/mysql-5.7.35/log/slow_query.log

lower_case_table_names = 1

[mysqld_safe]
lower_case_table_names = 1

log-error=/usr/local/mysql-5.7.35/log/mysqld.log
pid-file=/usr/local/mysql-5.7.35/run/mysqld.pid

  

  1.3 初始化Mysql

bin/mysqld --defaults-file=/usr/local/mysql-5.7.35/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql-5.7.35 --datadir=/data/mysql5.7 --console --lower-case-table-names=1

初始化时指定Mysql配置文件。

 

1.4 启动Mysql

通过support-files下面的myslq.server命令启动Mysql 5.7。
也可以通过配置/etc/systemd/system/mysqld5.7.service,使用systemctl工具来管理Mysql服务的启停。

vi /etc/systemd/system/mysqld5.7.service

[Unit]
Description=MySQL Server
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
ExecStart=/usr/local/mysql-5.7.35/bin/mysqld --defaults-file=/usr/local/mysql-5.7.35/my.cnf
LimitNOFILE = 5000

  

1.4 连接Mysql

[root@Mysqltest support-files]# mysql -uroot -S /usr/local/mysql-5.7.35/mysql.sock -pXXXXXX
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.7.35-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

  注意:

  1.输入的XXXXXX密码为初始化时产生的随机密码;
  2.此处连接必须指定socket文件,才能正常连接到第二个Mysql实例。

  第二个版本的Mysql安装完成。

 

原文地址:https://www.cnblogs.com/caoyibin/p/15476734.html