#/bin/bash# 1: 创建数据库安装目录,数据存放目录,日志目录,tmp目录mkdir -p /data/mysql3307/{data,logs,tmp}yum install -y libaio# 2: 下载官网mysql-5.7.22版本安装包wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz# 3: 安装包移动到安装数据库文件路径mv mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz /data/mysql3307# 4: 切换到mysql安装路径cd /data/mysql3307/# 5: 解压mysql安装包tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz# 6: 更改mysql文件夹名mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql-5.7.22# 7: 创建mysql用户useradd -s /bin/bash mysql# 8:切换到 /data/mysql3307/mysql-5.7.22目录cd /data/mysql3307/mysql-5.7.22# 9:创建mysql配置文件cat >/data/mysql3307/mysql-5.7.22/my.cnf <<EOF[client]port = 3307socket = /data/mysql3307/tmp/mysql.sock[mysql]prompt="\u@mysqldb \R:\m:\s [\d]> "no-auto-rehash[mysqld]user = mysqlport = 3307basedir = /data/mysql3307/mysqldatadir = /data/mysql3307/datasocket = /data/mysql3307/tmp/mysql.sockpid-file = /data/mysql3307/data/mysqldb.pidcharacter-set-server = utf8mb4skip_name_resolve = 1skip-slave-startopen_files_limit = 65535back_log = 1024max_connections = 5000max_connect_errors = 1000000table_open_cache = 1024table_definition_cache = 1024table_open_cache_instances = 64thread_stack = 512Kexternal-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 4Mjoin_buffer_size = 4Mthread_cache_size = 7500query_cache_size = 0query_cache_type = 0interactive_timeout = 600wait_timeout = 600tmp_table_size = 32Mmax_heap_table_size = 32Mslow_query_log = 1slow_query_log_file = /data/mysql3307/logs/slow3307.loglog-error = /data/mysql3307/logs/error.loglong_query_time = 0.1log_queries_not_using_indexes =1log_throttle_queries_not_using_indexes = 60min_examined_row_limit = 100log_slow_admin_statements = 1log_slow_slave_statements = 1server-id = 3307203log-bin = /data/mysql3307/logs/mybinlogsync_binlog = 1binlog_cache_size = 4Mmax_binlog_cache_size = 1Gmax_binlog_size = 1Gexpire_logs_days = 15master_info_repository = TABLErelay_log_info_repository = TABLEgtid_mode = onenforce_gtid_consistency = 1log_slave_updatesbinlog_format = rowbinlog_checksum = 1relay_log_recovery = 1relay-log-purge = 1key_buffer_size = 32Mread_buffer_size = 8Mread_rnd_buffer_size = 4Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 1Gmyisam_repair_threads = 1lock_wait_timeout = 3600explicit_defaults_for_timestamp = 1innodb_thread_concurrency = 0innodb_sync_spin_loops = 100innodb_spin_wait_delay = 30#slavereplicate-wild-do-table=k8_server1_log.%replicate-wild-do-table=k8_server2_log.%transaction_isolation = REPEATABLE-READ#innodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 1Ginnodb_buffer_pool_instances = 4innodb_buffer_pool_load_at_startup = 1innodb_buffer_pool_dump_at_shutdown = 1innodb_data_file_path = ibdata1:1G:autoextendinnodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5Ginnodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 32Minnodb_log_file_size = 1Ginnodb_log_files_in_group = 2innodb_max_undo_log_size = 1G#根据您的服务器IOPS能力适当调整#一般配普通SSD盘的话,可以调整到 10000 - 20000#配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000innodb_io_capacity = 3000innodb_io_capacity_max = 8000innodb_flush_neighbors = 0innodb_write_io_threads = 8innodb_read_io_threads = 8innodb_purge_threads = 4innodb_page_cleaners = 4innodb_open_files = 65535innodb_max_dirty_pages_pct = 50innodb_flush_method = O_DIRECTinnodb_lru_scan_depth = 4000innodb_checksums = 1innodb_checksum_algorithm = crc32#innodb_file_format = Barracuda#innodb_file_format_max = Barracudainnodb_lock_wait_timeout = 10innodb_rollback_on_timeout = 1innodb_print_all_deadlocks = 1innodb_file_per_table = 1innodb_online_alter_log_max_size = 4Ginternal_tmp_disk_storage_engine = InnoDBinnodb_stats_on_metadata = 0innodb_status_file = 1#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快innodb_status_output = 0innodb_status_output_locks = 0#performance_schemaperformance_schema = 1performance_schema_instrument = '%=on'#innodb monitorinnodb_monitor_enable="module_innodb"innodb_monitor_enable="module_server"innodb_monitor_enable="module_dml"innodb_monitor_enable="module_ddl"innodb_monitor_enable="module_trx"innodb_monitor_enable="module_os"innodb_monitor_enable="module_purge"innodb_monitor_enable="module_log"innodb_monitor_enable="module_lock"innodb_monitor_enable="module_buffer"innodb_monitor_enable="module_index"innodb_monitor_enable="module_ibuf_system"innodb_monitor_enable="module_buffer_page"innodb_monitor_enable="module_adaptive_hash"sql_mode=NO_ENGINE_SUBSTITUTION[mysqldump]quickmax_allowed_packet = 32MEOF# 10:给数据库文件夹下所有授权myql管理chown -R mysql:mysql /data/mysql3307/# 11:初始化mysql./bin/mysqld --defaults-file=/data/mysql3307/mysql-5.7.22/my.cnf --initialize --user=mysql --basedir=/data/mysql3307/mysql-5.7.22 --datadir=/data/mysql3307/data# 12:启动mysqlbin/mysqld --defaults-file=/data/mysql3307/mysql-5.7.22/my.cnf --user=mysql --basedir=/data/mysql3307/mysql-5.7.22 --datadir=/data/mysql3307/data &# 13: 查看自动生成的随机密码# cat /data/mysql3307/logs/error.log# 14:登录mysql方式# /data/mysql3307/mysql-5.7.22/bin/mysql -uroot -p -S /data/mysql3307/tmp/mysql.sock# 15: 重置MySQL密码# alter user 'root'@'localhost' identified by 'hadoop';# flush privileges;# 16: 停止mysql服务#/data/mysql3307/mysql-5.7.22/bin/mysqladmin -uroot -p -S /data/mysql3307/tmp/mysql.sock shutdown