快速安装MySQL脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了快速安装MySQL脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash # auto install mysql INSTALL_BASE="/usr/local" MYSQL_BASE="/usr/local/mysql" MYSQL_DATA="/data/mysql/3306" MY_CNF="/data/mysql/3306/my.cnf" USER="mysql" #MYSQL_DIR="mysql-5.7.19-linux-glibc2.5-x86_64.tar.gz" MYSQL_TAR="mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz" MYSQL_TAR_DIR=/software SOURCE_MYSQL_DIR="mysql-5.7.19-linux-glibc2.12-x86_64" PATH="export PATH=$PATH:$MYSQL_BASE/bin" download_mysql(){ #wget -qO $MYSQL_TAR $MYSQL_URL #tar -xf $MYSQL_TAR if [ ! -d $MYSQL_DATA ];then mkdir $MYSQL_DATA fi cd $MYSQL_TAR_DIR tar -xf $MYSQL_TAR mkdir -p $MYSQL_DATA/{data,logs,tmp} ln -s `pwd`/SOURCE_MYSQL_DIR $MYSQL_BASE chown -R mysql:mysql /usr/local/mysql/ chown -R mysql:mysql /data/mysql/3306/ id $USER if [ $? = 0 ];then echo "user exist" else echo -e "\033[5;31muser not exist\033[0m" groupadd mysql useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -M -n mysql fi } download_mysql create_mycnf(){ cat > $MY_CNF <<EOF #my.cnf [client] port = 3306 socket = /tmp/mysql3306.sock [mysql] prompt="\\[email protected]\\h:\\p [\\d]>" #pager="less -i -n -S" #tee=/data/mysql/3306/query.log no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /home/mysql/3306/data port = 3306 socket = /tmp/mysql3306.sock event_scheduler = 0 sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION explicit_defaults_for_timestamp=1 tmpdir = /data/mysql/3306/tmp #timeout interactive_timeout = 3600 wait_timeout = 3600 #character set character-set-server = utf8 #rpl_semi_sync_master_enabled = 1 #rpl_semi_sync_master_timeout = 2000 open_files_limit = 65535 max_connections = 500 max_connect_errors = 100000 lower_case_table_names =1 #symi replication #rpl_semi_sync_master_enabled=1 #rpl_semi_sync_master_timeout=1000 # 1 second #rpl_semi_sync_slave_enabled=1 #logs log-output=file slow_query_log = 1 slow_query_log_file = slow.log log-error = error.log log_warnings = 2 pid-file = mysql.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #binlog #binlog_format = STATEMENT binlog_format = row server-id = 13306 log-bin = /data/mysql/3306/logs/mysql-bin binlog_cache_size = 4M max_binlog_size = 256M max_binlog_cache_size = 1M sync_binlog = 0 expire_logs_days = 10 #procedure log_bin_trust_function_creators=1 # gtid-mode = on enforce-gtid-consistency=1 #relay log skip_slave_start = 1 max_relay_log_size = 128M relay_log_purge = 1 relay_log_recovery = 1 relay-log=relay-bin relay-log-index=relay-bin.index log_slave_updates relay_log=/data/mysql/3306/logs/relay_3306 #slave-skip-errors=1032,1053,1062 #skip-grant-tables #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 128K join_buffer_size = 128K thread_cache_size = 200 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 1G myisam_repair_threads = 1 #innodb #innodb_buffer_pool_size = 10G innodb_buffer_pool_size = 1G innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:1024M:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M innodb_log_file_size = 100M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 200 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT EOF } create_mycnf yum install libaio* init_mysql(){ /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --user=mysql --initialize echo $PATH >>/etc/profile /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & } init_mysql MYSQL_PASS="`cat /data/mysql/3306/data/error.log |grep "[email protected]"|awk -F " " ‘{print $11}‘`" echo $MYSQL_PASS
以上是关于快速安装MySQL脚本的主要内容,如果未能解决你的问题,请参考以下文章