你的位置:首页 > 数据库

[数据库]mysql多实例安装脚本


#! /bin/bash# v.mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz# only install master mysql# time:2016-08-15# pkg dirpkg_dir=`pwd`# mysql base dirdata_dir="/data/mysql_root/mysql"base_dir="/usr/local/mysql"# create MySQL group and userecho "start create mysql group and user" >> ${pkg_dir}/install.loggroupadd mysqluseradd -g mysql mysql -s /sbin/nologinecho "end mysql group and user" >> ${pkg_dir}/install.log# mysql datafile path# install mysqld # grant privilegesmkdir -p ${data_dir}/data 2>/dev/nullchown -R mysql:mysql ${data_dir}/data# un_tar.gz and install mysql programmerecho "start un_tar.gz..." >> ${pkg_dir}/install.logcd ${pkg_dir} && tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local && cd /usr/local && mv mysql-5.6.30-linux-glibc2.5-x86_64 mysql;echo "end install mysql" >> ${pkg_dir}/install.logecho "set mysql my.cnf params" >> ${pkg_dir}/install.log# stored mysqld multi execute logmkdir -p ${base_dir}/multi_log 2>/dev/null# comm parameter of my.cnf cat<<EOF > ${base_dir}/my.cnf# The mysqld multi instance[mysqld_multi]mysqld = ${base_dir}/bin/mysqld_safemysqladmin = ${base_dir}/bin/mysqladminlog =${base_dir}/multi_log/mysqld_multi.log[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash[myisamchk]key_buffer_size = 256Msort_buffer_size = 256Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeoutEOF# other my.cnf parameter part pre_install_mysqld(){cat<<EOF >> ${base_dir}/my.cnf# The MySQL server[mysqld${port:2}]port		= ${port} socket		= ${data_dir}/data${port}/mysql.socketmax-connections = 800skip-name-resolveskip-external-lockingkey_buffer_size = 384Mmax_allowed_packet = 1073M table_open_cache = 512sort_buffer_size = 512K read_buffer_size = 512Kread_rnd_buffer_size = 512Kjoin_buffer_size = 128Kmyisam_sort_buffer_size = 64Mthread_cache_size = 256query_cache_size = 0query_cache_type = 0tmp_table_size = 64Mmax_heap_table_size = 64Mbasedir=${base_dir}datadir=${data_dir}/data${port}pid-file = ${data_dir}/data${port}/mysql.pidlog_error = ${data_dir}/data${port}/mysql.err# set binary logging is required for replicationlog-bin=mysql-binbinlog_cache_size = 32M# event_scheduler shutoff in mysqld slaveevent_scheduler = 1 binlog_format=rowexpire_logs_days = 3# set slow logslow_query_log = 1long_query_time = 2#set 字符character_set_server = utf8#set 大小写敏感lower_case_table_names=1# set mysqld server_idserver-id	= ${port}# set innodb paramsinnodb_data_home_dir = ${data_dir}/data${port} innodb_log_group_home_dir = ${data_dir}/data${port} innodb_buffer_pool_size = 5972Minnodb_additional_mem_pool_size = 10Minnodb_log_file_size = 512Minnodb_log_buffer_size = 16Minnodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECTinnodb_file_per_table = 1innodb_lock_wait_timeout = 10innodb_file_format = Barracudainnodb_file_format_max = Barracudainnodb_stats_on_metadata = 0innodb_purge_threads = 1innodb_read_io_threads = 12innodb_write_io_threads = 12innodb_purge_threads = 1innodb_open_files = 500innodb_thread_concurrency = 0innodb_io_capacity = 600[client]default-character-set = utf8EOF# initizal mysql Db chmod +x ${base_dir}/scripts/mysql_install_db${base_dir}/scripts/mysql_install_db --basedir=${base_dir} --datadir=${data_dir}/data${port} --user=mysql --defaults-file=${base_dir}/my.cnf >> ${pkg_dir}/install.logecho "end mysqld install." >> ${pkg_dir}/install.log}# mysql datafile pathfor port in 2016 3017 4018 5019 6020 do    # check mysql base and data dir folder    if [ ! -d ${data_dir}/data${port} ];then        mkdir -p ${data_dir}/data${port}        # function mysqld_install to mysql programmer        pre_install_mysqld $port    else        pre_install_mysqld $port    fidone#mysql datachown -R mysql:mysql ${data_dir}/datachown -R mysql:mysql ${base_dir}/data#环境变量echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profilesource /etc/profile