mysql多版本例項安裝

z597011036發表於2021-05-23

 mysql多例項在一臺資源足夠的情況下管理多個資料庫,其中包括安裝一個資料庫軟體初使化多個資料目錄,埠不一樣就可以。還可安裝不同資料庫版本來統一管理,各例項資料不共享。

1.安裝mysql5.6資料庫  
[root@test01 ~]# yum -y install autoconf  libaio*    --mysql5.6依賴autoconf包,mysql5.7依賴libaio包。
[root@test01 ~]# ll
total 2310240
-rw-------. 1 root root       1421 Aug  5  2019 anaconda-ks.cfg
-rw-r--r--. 1 root root  328563044 May 23 12:17 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--. 1 root root  661718255 May 21 17:54 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--. 1 root root 1375394901 May  7 00:31 Percona-Server-8.0.23-14-Linux.x86_64.glibc2.17.tar.gz
[root@test01 ~]# tar xvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@test01 ~]# tar xvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@test01 ~]# tar xvf Percona-Server-8.0.23-14-Linux.x86_64.glibc2.17.tar.gz -C /usr/local/
[root@test01 ~]# cd /usr/local/
[root@test01 local]# mv mysql-5.6.40-linux-glibc2.12-x86_64/  mysql-5.6.40
[root@test01 local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql-5.7.33
[root@test01 local]# mv Percona-Server-8.0.23-14-Linux.x86_64.glibc2.17/ Percona-Server-8.0.23
[root@test01 local]# cd mysql-5.6.40/
[root@test01 mysql-5.6.40]# ./scripts/mysql_install_db --user=mysql  --group=mysql  --basedir=/usr/local/mysql-5.6.40/ --datadir=/usr/local/mysql-5.6.40/data
[root@test01 mysql-5.6.40]# cp -a support-files/mysql.server  /etc/init.d/mysql5.6
[root@test01 mysql-5.6.40]# chkconfig --add mysql5.6
[root@test01 mysql-5.6.40]# chkconfig  mysql5.6 on
[root@test01 mysql-5.6.40]# vim  /usr/local/mysql-5.6.40/my.cnf
[mysqld]
basedir = /usr/local/mysql-5.6.40
datadir = /usr/local/mysql-5.6.40/data
port = 3306
server_id = 10
[root@test01 mysql-5.6.40]# vim /etc/init.d/mysql5.6
basedir=/usr/local/mysql-5.6.40
datadir=/usr/local/mysql-5.6.40/data
conf=/usr/local/mysql-5.6.40/my.cnf
[root@test01 mysql-5.6.40]# /etc/init.d/mysql5.6 start
Starting MySQL.Logging to '/usr/local/mysql-5.6.40/data/test01.err'.
. SUCCESS!
[root@test01 mysql-5.6.40]#

2.安裝mysql5.7資料庫(安裝方法與mysql5.6不一樣)
[root@test01 mysql-5.7.33]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.33/ --datadir=/usr/local/mysql-5.7.33/data
2021-05-23T06:35:35.375853Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see document
ation for more details).2021-05-23T06:36:20.825902Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-23T06:36:22.319561Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-23T06:36:22.637220Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new
 UUID: 30af30d2-bb91-11eb-a024-00505693d5b3.2021-05-23T06:36:22.675831Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-23T06:36:24.471795Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-23T06:36:24.862429Z 1 [Note] A temporary password is generated for root@localhost: m5/Gw+pRl#Lr     --預設初使密碼
[root@test01 mysql-5.7.33]# cp -a support-files/mysql.server  /etc/init.d/mysql5.7
[root@test01 mysql-5.7.33]# chkconfig --add mysql5.7
[root@test01 mysql-5.7.33]# chkconfig mysql5.7 on
[root@test01 mysql-5.7.33]# vim my.cnf
[mysqld]
basedir = /usr/local/mysql-5.7.33
datadir = /usr/local/mysql-5.7.33/data
port = 3307
server_id = 20
[root@test01 mysql-5.7.33]# vim /etc/init.d/mysql5.7
basedir=/usr/local/mysql-5.7.33
datadir=/usr/local/mysql-5.7.33/data
conf=/usr/local/mysql-5.7.33/my.cnf
[root@test01 mysql-5.7.33]# /etc/init.d/mysql5.7 start
Starting MySQL.Logging to '/usr/local/mysql-5.7.33/data/test01.err'.
 SUCCESS!
[root@test01 mysql-5.7.33]#

3.安裝Percona-Server8.0資料庫
[root@test01 local]# cd Percona-Server-8.0.23/
[root@test01 Percona-Server-8.0.23]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/Percona-Server-8.0.23/ --datadir=/usr/local/Percona-Server-8.0.23/da
ta2021-05-23T06:51:18.058721Z 0 [System] [MY-013169] [Server] /usr/local/Percona-Server-8.0.23/bin/mysqld (mysqld 8.0.23-14) initializing of server in progress as proc
ess 163582021-05-23T06:51:18.201151Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-05-23T06:51:32.631345Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-05-23T06:51:48.164084Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: P-Vkfhobh3>k      --預設初使密碼
[root@test01 Percona-Server-8.0.23]# chkconfig --add Percona8.0
[root@test01 Percona-Server-8.0.23]# chkconfig  Percona8.0 on
[root@test01 Percona-Server-8.0.23]# vim my.cnf
[mysqld]
basedir = /usr/local/Percona-Server-8.0.23
datadir = /usr/local/Percona-Server-8.0.23/data
port = 3308
server_id = 30
[root@test01 Percona-Server-8.0.23]# /etc/init.d/Percona8.0 start
Starting MySQL (Percona Server)... SUCCESS!
[root@test01 Percona-Server-8.0.23]#

4.配置mysqld_multi多例項檔案
[root@test01 ~]# cp -a /usr/local/Percona-Server-8.0.23/support-files/mysqld_multi.server  /etc/init.d/mysqld_multi
[root@test01 ~]# vim /etc/my.cnf
[mysqld_multi]    --公共配置
user=root
pass=123456     --這裡的密碼配置是pass不是password。
mysqld=/usr/local/Percona-Server-8.0.23/bin/mysqld_safe  --如果是多個版本資料庫,以下兩行可不寫。如果是一個資料庫不同資料檔案這兩行要寫。
mysqladmin=/usr/local/Percona-Server-8.0.23/bin/mysqladmin
log=/var/log/mysql.log      --多例項啟動和停止日誌檔案
[mysqld56]         --名稱必須是mysqld開頭,56之間不能有點或橫線。
basedir = /usr/local/mysql-5.6.40
datadir = /usr/local/mysql-5.6.40/data
port = 3306
server_id = 10
socket = /usr/local/mysql-5.6.40/mysql.sock
mysqld=/usr/local/mysql-5.6.40/bin/mysqld_safe    --啟動資料庫命令
mysqladmin=/usr/local/mysql-5.6.40/bin/mysqladmin  --關閉資料庫命令
[mysqld57]
basedir = /usr/local/mysql-5.7.33
datadir = /usr/local/mysql-5.7.33/data
port = 3307
server_id = 20
socket=/usr/local/mysql-5.7.33/mysql.sock
mysqld=/usr/local/mysql-5.7.33/bin/mysqld_safe
mysqladmin=/usr/local/mysql-5.7.33/bin/mysqladmin
[mysqld80]
basedir = /usr/local/Percona-Server-8.0.23
datadir = /usr/local/Percona-Server-8.0.23/data
port = 3308
server_id = 30
socket=/usr/local/Percona-Server-8.0.23/mysql.sock
mysqld=/usr/local/Percona-Server-8.0.23/bin/mysqld_safe
mysqladmin=/usr/local/Percona-Server-8.0.23/bin/mysqladmin
[root@test01 ~]# /etc/init.d/mysqld_multi report
Reporting MySQL (Percona Server) servers
MySQL (Percona Server) from group: mysqld56 is running
MySQL (Percona Server) from group: mysqld57 is running
MySQL (Percona Server) from group: mysqld80 is running
[root@test01 ~]# /etc/init.d/mysqld_multi stop 56,57      --關閉56,57例項
[root@test01 ~]# /etc/init.d/mysqld_multi report
Reporting MySQL (Percona Server) servers
MySQL (Percona Server) from group: mysqld56 is not running
MySQL (Percona Server) from group: mysqld57 is not running
MySQL (Percona Server) from group: mysqld80 is running
[root@test01 ~]# /etc/init.d/mysqld_multi start 56
[root@test01 ~]# /etc/init.d/mysqld_multi report
Reporting MySQL (Percona Server) servers
MySQL (Percona Server) from group: mysqld56 is running
MySQL (Percona Server) from group: mysqld57 is not running
MySQL (Percona Server) from group: mysqld80 is running
[root@test01 ~]#

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25854343/viewspace-2773545/,如需轉載,請註明出處,否則將追究法律責任。

相關文章