Mysql multi-instance installation script and mysql instance installation script
#! /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-s/sbin/nologinecho "end mysql group and user" >$ {pkg_dir}/install. lo G # 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/logs =$ {base_dir}/bin/mysqladminlog =$ {base_dir}/multi_log/mysqld_multi.log [mysqldump] quickmax_allowed_packet = 16 M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 256Msort_buffer_size = 256Mread_buffer = 2Mwrite_buffer = 2 M [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 = Bytes = 1073 M table_open_cache = bytes = 512 K read_buffer_size = bytes = 0query_cache_type = 0tmp_table_size = bytes = 64 Mbasedir =$ {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 = 32 M # event_scheduler shutoff in mysqld encoding = 1 binlog_format = encoding = 3 # set slow logslow_query_log = 1long_query_time = 2 # set characters character_set_server = utf8 # set case sensitive lower_case_table_names = 1 # set mysqld server_idserver-id =$ {port} # set innodb paramsinnodb_dat A_home_dir =$ {data_dir}/data $ {port} innodb_log_group_home_dir =$ {data_dir}/data $ {port} bytes = 2 innodb_flush_method = bytes = 10innodb_file_format = Barracudainnodb_file_format_max = Barracudainnod B _stats_on_metadata = bytes = 1innodb_open_files = bytes = 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 # environment variable echo 'export PATH = $ PATH: /usr/local/mysql/bin'>/etc/profilesource/etc/profile