1. 程式人生 > 其它 >Linux環境下Mysql多版本部署

Linux環境下Mysql多版本部署

  安裝環境:OS:Centos 7.9

已經安裝的Mysql:Mysql 8.0.26 安裝目錄:/usr/local/mysql

  需要安裝的Mysql版本:Mysql 5.7.35

  多版本安裝思路:Mysql安裝目錄、資料檔案目錄、pid檔案、socket檔案,監聽埠,配置檔案等都設定不同的位置。

  1.安裝過程:

  1.1解壓安裝包

cd /usr/local
tar zxvfmysql-5.7.35-el7-x86_64.tar.gz -C /usr/local/
mvmysql-5.7.35-el7-x86_64mysql-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安裝完成。