目標:一臺服務器開多個mysql實例mysql
到官網下週mysql源碼包,而後經過腳本安裝c++
#!/bin/bash yum install -y ncurses-devel cmake gcc perl-Data-Dumper gcc-c++ useradd -s /sbin/nologin -r -M mysql tar -xzf mysql-boost-5.7.13.tar.gz cd mysql-5.7.13 cp support-files/my-default.cnf /etc/my.cnf make clean cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0 -DENABLED_LOCAL_INFILE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost/ make -j 2 make install mkdir /data/mysql -p chown mysql:mysql /data/mysql/ chown mysql:mysql -R /usr/local/mysql/ /usr/local/mysql/bin/mysqld --initialize --user=mysql
初始化完成以後,/data/mysql這裏是一個實例
注意:初始化完成會提供一個初始root密碼給你的,要記得改sql
添加mysql環境變量bash
[root@k8s mysql-5.7.13]# echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile [root@k8s mysql-5.7.13]# source /etc/profile
安裝完成
[mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld mysqladmin = /usr/local/mysql/bin/mysqladmin log = /tmp/mysql_multi.log #加入以上配置 #第一個實例,也就是剛安裝完初始化的那個實例 [mysqld1] basedir = /usr/local/mysql datadir = /data/mysql port = 3306 server_id = 101 socket = /tmp/mysqld.sock user = mysql #gtid配置,可選 gtid_mode=on enforce_gtid_consistency=on log-slave-updates=on log-bin=mysql-bin binlog_format=mixed sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #第二個實例 [mysqld2] basedir = /usr/local/mysql datadir = /data/3307 port = 3307 server_id = 102 socket = /tmp/mysqld2.sock user = mysql #gtid配置,可選 gtid_mode=on enforce_gtid_consistency=on log-slave-updates=on log-bin=mysql-bin binlog_format=mixed #從庫設置只讀 read-only
指定data目錄,執行命令初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/3307
初始化完成會提供一個初始root密碼給你的,要記得改服務器
啓動實例,經過mysqld_multi 啓動[root@k8s mysql-5.7.13]# mysqld_multi start
socket
查看多實例狀態ide
[root@k8s mysql-5.7.13]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld1 is running MySQL server from group: mysqld2 is running
啓動完成code