mysql-5.7.20源碼安裝 + 多實例 + 主從復制
1、更換yum源
wget -O /etc/yum.repos.d/eprl.repo http://mirrors.aliyun.com/repo/epel-6.repo
2、安裝cmake
tar xf cmake-3.0.0.tar.gz
cd cmake-3.0.0
./bootstrap
make
make install
2、安裝boost
tar -zxvf boost_1_59_0.tar.gz -C /usr/local/
3、創建安裝目錄及所需要文件
mkdir -p /application/mysql-5.7.22/{data,logs,pids}
touch /application/mysql-5.7.22/logs/mysqld.log
touch /application/mysql-5.7.22/pids/mysqld.pid
4、安裝依賴軟件包
yum -y install ncurses ncurses-devel bison libgcrypt perl
5、創建用戶
useradd mysql -s /sbin/nologin -M
6、解壓並安裝
tar xf mysql-5.7.22.tar.gz
cd mysql-5.7.22
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.22 -DMYSQL_DATADIR=/application/mysql-5.7.22/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
make
make install
7、創建軟連接
ln -s /application/mysql-5.7.22 /application/mysql
8、添加環境變量
echo "PATH=/application/mysql/bin:/application/mysql/lib:$PATH" >>/etc/profile
source /etc/profile
9、初始化
mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
10、復制啟動命令
/bin/cp support-files/mysql.server /etc/init.d/mysqld
11、修改/etc/my.cnf
[mysqld]
datadir=/application/mysql/data
socket=/application/mysql/mysql.sock
[mysqld_safe]
log-error=/application/mysql/logs/mysqld.log
pid-file=/application/mysql/pids/mysqld.pid
symbolic-links=0
[client]
default-character-set=utf8
socket=/application/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/application/mysql/mysql.sock
12、修改mysql安裝目錄的屬主
chown -R mysql.mysql /application/mysql
13、啟動
/etc/init.a/mysqld start
14、修改密碼
mysqladmin -uroot -S /application/mysql/mysql.sock password '123456'
《配置多實例》
1、關閉mysql
/etc/init.d/mysqld stop
2、創建所所需要目錄及文件
mkdir -p /data/{3306,3307}/data
touch /data/{3306,3307}/mysql.pid
touch /data/{3306,3307}/error.log
chown -R mysql.mysql /data/
3、初始化
mysqld --no-defaults --initialize-insecure --basedir=/application/mysql-5.7.22 --datadir=/data/3306/data/ --user=mysql --explicit_defaults_for_timestamp
4、分配獨立配置文件
#配置文件優先級,/etc/與basedir目錄下不要存在my.cnf配置文件
/etc/my.cnf >basedir/my.cnf >datadir/my.cnf
vim /data/3306/my.cnf
#可自由選擇,參數來自網絡
[mysqld]
port= 3306
socket= /data/3306/mysql.sock
datadir= /data/3306/data
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
log-error= /data/3306/error.log
pid-file= /data/3306/mysql.pid
explicit_defaults_for_timestamp = true
max_connections = 100
max_connect_errors = 5
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_data_home_dir = /data/3306/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/3306/data
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
5、啟動測試
mysqld_safe --defaults-file=/data/3306/my.cnf
6、mysql啟動腳本
#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd="$2"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
function start () {
if [ ! -e "${mysql_sock}" ];then
printf "Starting MySQL...\n"
/bin/bash ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &
else
printf "MySQL is running...\n"
exit
fi
}
function stop () {
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stoping...\n"
exit
else
printf "Stoping MySQL..."
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
function restart () {
printf "Restarting MySQL...\n"
stop
sleep 2
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
printf "Usage: /data/${port}/mysql{start|stop|restart}\n"
esac
$*
mysql-5.7.20源碼安裝 + 多實例 + 主從復制