#!/bin/sh # Description: 安裝mysql-5.6.31 SOFTWARE_DIR='/root/' # ERROR Output error_echo(){ printf "\033[31m $* \033[0m\n" } # 安裝mysql插件包 mysql_package_install(){ cd ${SOFTWARE_DIR} && tar zxf bison-2.7.tar.gz -C /usr/src/ && cd /usr/src/bison-2.7/ && ./configure && make && make install cd ${SOFTWARE_DIR} && tar zxf ncurses-5.9.tar.gz -C /usr/src/ && cd /usr/src/ncurses-5.9/ && ./configure && make && make install } # 建立mysql用戶 mysql_user_create(){ groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql mkdir -p /data/mysql/ } # 安裝mysql mysql_install(){ cd ${SOFTWARE_DIR} && tar zxf mysql-5.6.31.tar.gz -C /usr/src/ && cd /usr/src/mysql-5.6.31/ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_READLINE=1 -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 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DWITH_PARTITION_STORAGE_ENGINE=1 make && make install } # 初始化mysql mysql_initialization(){ cd ${SOFTWARE_DIR} rm -rf /usr/local/mysql/my.cnf && mv /etc/my.cnf /etc/my.cnf.bak \cp -r my.cnf /usr/local/mysql/ && dos2unix /usr/local/mysql/my.cnf && ln -sf /usr/local/mysql/my.cnf /etc/my.cnf /usr/local/mysql/scripts/mysql_install_db --defaults-file=/usr/local/mysql/my.cnf --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql/ } # 配置mysql mysql_config(){ cp /usr/local/mysql/bin/* /usr/bin/ echo /usr/local/mysql/lib/ >> /etc/ld.so.conf.d/mysql-x86_64.conf echo /usr/lib64/mysql/ >> /etc/ld.so.conf.d/mysql-x86_64.conf cp /etc/ld.so.conf.d/mysql-x86_64.conf /etc/ld.so.conf.d/mysql.conf ldconfig } # 配置mysql啓動腳本 mysql_init(){ cp /usr/src/mysql-5.6.31/support-files/mysql.server /etc/init.d/mysqld chmod a+x /etc/init.d/mysqld chkconfig --add mysqld && chkconfig --level 2345 mysqld on } main(){ mysql_package_install; mysql_user_create; mysql_install; mysql_initialization; mysql_config; mysql_init; if [ $? -eq 0 ]; then /etc/init.d/mysqld start
echo "mysql install successfully !!!" else error_echo "mysql install failed !!!" fi } main
[client] port = 3306 socket = /data/mysql/mysql.sock character-set-server = utf8mb4 [mysqld] user = mysql port = 3306 datadir = /data/mysql/ basedir = /usr/local/mysql/ socket = mysql.sock pid-file = mysql.pid log_error = mysql-error.log server-id = 1 init-connect = 'SET NAMES utf8mb4' character-set-server = utf8mb4 log-bin = mysql-bin binlog_format = mixed binlog_cache_size = 16M expire_logs_days = 30 slow_query_log = 1 long_query_time = 1 slow_query_log_file = mysql-slow.log open_files_limit = 65535 table_open_cache = 65535 table_definition_cache = 65535 key_buffer_size = 8M sort_buffer_size = 2M join_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 2M back_log = 600 max_connections = 100 max_user_connections = 0 max_connect_errors = 1024 max_prepared_stmt_count = 1024 max_allowed_packet = 8M max_heap_table_size = 16M max_tmp_tables = 32 tmp_table_size = 16M thread_cache_size = 32 ft_min_word_len = 4 query_cache_type = 0 query_cache_size = 0 performance_schema = 0 explicit_defaults_for_timestamp lower_case_table_names = 1 wait_timeout = 28800 interactive_timeout = 28800 skip-slave-start skip-external-locking skip-name-resolve skip-character-set-client-handshake sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" default-storage-engine = InnoDB innodb_open_files = 65535 innodb_data_file_path = ibdata1:1G:autoextend innodb_file_format = Barracuda innodb_strict_mode = 1 innodb_file_per_table = 1 innodb_buffer_pool_size = 512M innodb_buffer_pool_instances = 8 innodb_log_buffer_size = 64M innodb_log_file_size = 1G innodb_log_files_in_group = 2 innodb_read_io_threads = 4 innodb_write_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 0 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 innodb_autoextend_increment = 100 innodb_flush_method = O_DIRECT innodb_io_capacity = 20000 innodb_io_capacity_max = 40000