zoukankan      html  css  js  c++  java
  • Centos 6.10下安装MySQL5.6.48

    一: 安装依赖

    安装依赖包

    yum install libaio numactl libncurses*  -y

    二:创建用户

    groupadd -f mysql
    useradd -r -g mysql mysql

    三:创建数据目录

    mkdir -p /data/mysql_data 
    chown mysql:mysql /data/mysql_data -R

    四: 这里我们引入阿里云的MySQL5.6 高可用的配置模板

    该配置模板好像不包括 主从复制的配置参数

    [mysqld]
    innodb_flush_log_at_trx_commit=
    innodb_buffer_pool_load_at_startup=OFF
    bulk_insert_buffer_size=4194304
    ft_query_expansion_limit=20
    innodb_old_blocks_time=1000
    innodb_stats_sample_pages=8
    thread_stack=262144
    lc_time_names=en_US
    innodb_thread_concurrency=0
    sync_master_info=10000
    default_time_zone=+8:00
    old_passwords=0
    optimizer_search_depth=62
    loose_innodb_data_file_purge_interval=100
    innodb_compression_level=6
    max_sort_length=1024
    max_binlog_cache_size=18446744073709547520
    innodb_online_alter_log_max_size=134217728
    key_cache_block_size=1024
    innodb_adaptive_max_sleep_delay=150000
    query_alloc_block_size=8192
    loose_gap_lock_raise_error=OFF
    log_warnings=1
    innodb_lock_wait_timeout=50
    innodb_purge_threads=1
    innodb_compression_failure_threshold_pct=5
    innodb_compression_pad_pct_max=50
    loose_innodb_data_file_purge=ON
    binlog_rows_query_log_events=OFF
    innodb_stats_persistent_sample_pages=20
    innodb_ft_total_cache_size=640000000
    loose_rds_tablestat=OFF
    loose_max_statement_time=0
    innodb_flush_method=O_DIRECT
    eq_range_index_dive_limit=10
    loose_max_execution_time=0
    loose_optimizer_trace_features=greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
    connect_timeout=10
    innodb_purge_batch_size=300
    loose_rds_threads_running_high_watermark=50000
    div_precision_increment=4
    innodb_sync_array_size=1
    innodb_support_xa=ON
    innodb_stats_method=nulls_equal
    relay_log_recovery=OFF
    lock_wait_timeout=31536000
    net_read_timeout=30
    innodb_write_io_threads=4
    end_markers_in_json=OFF
    max_binlog_stmt_cache_size=18446744073709547520
    innodb_checksum_algorithm=innodb
    loose_innodb_data_file_purge_max_size=512
    query_cache_type=0
    innodb_ft_enable_diag_print=OFF
    loose_gap_lock_write_log=OFF
    innodb_ft_enable_stopword=ON
    innodb_io_capacity=20000
    slow_launch_time=2
    innodb_table_locks=ON
    innodb_stats_persistent=ON
    tmp_table_size=2097152
    disconnect_on_expired_password=ON
    loose_tokudb_auto_analyze=30
    default_storage_engine=InnoDB
    net_retry_count=10
    innodb_ft_cache_size=8000000
    binlog_cache_size=128KB
    innodb_max_dirty_pages_pct=75
    query_cache_limit=1048576
    innodb_disable_sort_file_cache=ON
    innodb_lru_scan_depth=1024
    innodb_ft_result_cache_limit=2000000000
    long_query_time=1
    interactive_timeout=7200
    innodb_read_io_threads=4
    transaction_prealloc_size=4096
    open_files_limit=65535
    innodb_open_files=3000
    max_heap_table_size=16777216
    automatic_sp_privileges=ON
    explicit_defaults_for_timestamp=false
    ft_max_word_len=84
    innodb_autoextend_increment=64
    loose_rds_max_tmp_disk_space=10737418240
    sql_mode=NO_ENGINE_SUBSTITUTION
    innodb_stats_transient_sample_pages=8
    innodb_random_read_ahead=OFF
    loose_innodb_rds_faster_ddl=OFF
    innodb_status_output=OFF
    innodb_log_compressed_pages=OFF
    slave_net_timeout=60
    delay_key_write=ON
    query_cache_wlock_invalidate=OFF
    general_log=OFF
    max_prepared_stmt_count=16382
    wait_timeout=86400
    query_cache_min_res_unit=4096
    innodb_print_all_deadlocks=OFF
    loose_thread_pool_size=1
    binlog_stmt_cache_size=32768
    transaction_isolation=READ-COMMITTED
    innodb_buffer_pool_dump_at_shutdown=OFF
    query_prealloc_size=8192
    key_cache_age_threshold=300
    transaction_alloc_block_size=8192
    optimizer_trace_limit=1
    metadata_locks_cache_size=1024
    optimizer_prune_level=1
    innodb_max_purge_lag=0
    innodb_max_dirty_pages_pct_lwm=0
    max_sp_recursion_depth=0
    innodb_status_output_locks=OFF
    updatable_views_with_limit=YES
    binlog_row_image=full
    loose_tokudb_buffer_pool_ratio=0
    innodb_change_buffer_max_size=25
    innodb_optimize_fulltext_only=OFF
    local_infile=ON
    innodb_ft_max_token_size=84
    loose_thread_pool_enabled=ON
    innodb_adaptive_hash_index=ON
    innodb_sync_spin_loops=30
    net_write_timeout=60
    flush_time=0
    lower_case_table_names=1
    character_set_filesystem=binary
    key_cache_division_limit=100
    delayed_insert_timeout=300
    preload_buffer_size=32768
    innodb_read_ahead_threshold=56
    concurrent_insert=1
    block_encryption_mode="aes-128-ecb"
    slow_query_log=ON
    net_buffer_length=16384
    query_cache_size=3145728
    innodb_buffer_pool_size=6144M
    delayed_insert_limit=100
    innodb_large_prefix=OFF
    innodb_monitor_disable=
    innodb_adaptive_flushing_lwm=10
    delayed_queue_size=1000
    innodb_thread_sleep_delay=10000
    loose_rds_set_connection_id_enabled=ON
    innodb_old_blocks_pct=37
    innodb_ft_sort_pll_degree=2
    log_slow_admin_statements=OFF
    innodb_stats_on_metadata=OFF
    stored_program_cache=256
    group_concat_max_len=10240
    innodb_sort_buffer_size=1048576
    innodb_spin_wait_delay=6
    myisam_sort_buffer_size=262144
    innodb_rollback_segments=128
    innodb_commit_concurrency=0
    innodb_concurrency_tickets=5000
    auto_increment_increment=1
    binlog_checksum=CRC32
    max_seeks_for_key=18446744073709500000
    max_length_for_sort_data=1024
    back_log=3000
    max_error_count=64
    innodb_io_capacity_max=40000
    innodb_strict_mode=OFF
    binlog_order_commits=ON
    min_examined_row_limit=0
    performance_schema=OFF
    innodb_ft_min_token_size=3
    sync_relay_log_info=10000
    innodb_stats_auto_recalc=ON
    max_connect_errors=100
    join_buffer_size=432KB
    innodb_change_buffering=all
    optimizer_trace_max_mem_size=16384
    innodb_autoinc_lock_mode=2
    innodb_rollback_on_timeout=OFF
    max_write_lock_count=102400
    master_verify_checksum=OFF
    innodb_ft_num_word_optimize=2000
    max_join_size=18446744073709551615
    loose_validate_password_length=8
    log_throttle_queries_not_using_indexes=0
    innodb_max_purge_lag_delay=0
    loose_optimizer_trace=enabled=off,one_line=off
    default_week_format=0
    innodb_cmp_per_index_enabled=OFF
    loose_rds_indexstat=OFF
    host_cache_size=643
    low_priority_updates=0
    auto_increment_offset=1
    range_alloc_block_size=4096
    ft_min_word_len=4
    sort_buffer_size=848KB
    slave_type_conversions=
    max_allowed_packet=1024M
    read_buffer_size=848KB
    thread_cache_size=256
    optimizer_trace_offset=-1
    loose_thread_pool_oversubscribe=32
    character_set_server=utf8
    innodb_adaptive_flushing=ON
    log_queries_not_using_indexes=OFF
    innodb_monitor_enable=
    innodb_flush_neighbors=0
    innodb_buffer_pool_instances=8

    五: 进行MySQL初始化

    #下载安装包 mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz

    cd /usr/local/
    tar zxf mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz
    ln -s mysql-5.6.48-linux-glibc2.12-x86_64 mysql
    /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data

    六:修改启动脚本

    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    vim /etc/init.d/mysqld
    #修改配置
    basedir=/usr/local/mysql
    datadir=/data/mysql_data

    七: 启动MySQL

    /etc/init.d/mysqld start

    八:进行安全配置

    /usr/local/mysql/bin/mysql_secure_installation

     如果在进行MySQL安全设置时报错误如下:

    Enter current password for root (enter for none):
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    此时则应该时mysql.sock的文件没有被正确找到,而且mysql_secure_installation 的并没有 -S 指定socket文件的选项。

    修改mysql_secure_installation文件,大约150行,在sub make_config定义中加入 "socket=/data/mysql/mysql.sock",修改完成如下

    sub make_config {
      my $password = shift;
    
      my $esc_pass = basic_single_escape($rootpass);
      write_file($config,
                 "# mysql_secure_installation config file",
                 "[mysql]",
                 "user=root",
                 "password='$esc_pass'",
                 "connect-expired-password",
                 "socket=/data/mysql/mysql.sock");  #根据自己的设置;添加这一行
    }

    九:最后是自动化安装脚本

    #!/bin/bash
    
    
    #Cetnos6 下自动化安装MySQL脚本
    
    echo "####安装依赖####"
    yum install libaio numactl libncurses*  -y
    sleep 1
    
    echo "####创建MySQL用户####"
    groupadd -f mysql
    useradd -r -g mysql mysql
    
    sleep 2
    
    echo "####-创建数据目录-####"
    mkdir -p /data/mysql_data
    chown mysql:mysql /data/mysql_data -R
    sleep 1
    
    echo "####-手动上传mysql5.6.48到/usr/local/目录-####"
    tar zxf mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz
    ln -s mysql-5.6.48-linux-glibc2.12-x86_64 mysql
    
    #导入mysql配置文件
    echo "引入阿里云MySQL配置文件模板"
    cat <<EOF > /etc/my.cnf
    [mysqld]
    innodb_flush_log_at_trx_commit=
    innodb_buffer_pool_load_at_startup=OFF
    bulk_insert_buffer_size=4194304
    ft_query_expansion_limit=20
    innodb_old_blocks_time=1000
    innodb_stats_sample_pages=8
    thread_stack=262144
    lc_time_names=en_US
    innodb_thread_concurrency=0
    sync_master_info=10000
    default_time_zone=+8:00
    old_passwords=0
    optimizer_search_depth=62
    loose_innodb_data_file_purge_interval=100
    innodb_compression_level=6
    max_sort_length=1024
    max_binlog_cache_size=18446744073709547520
    innodb_online_alter_log_max_size=134217728
    key_cache_block_size=1024
    innodb_adaptive_max_sleep_delay=150000
    query_alloc_block_size=8192
    loose_gap_lock_raise_error=OFF
    log_warnings=1
    innodb_lock_wait_timeout=50
    innodb_purge_threads=1
    innodb_compression_failure_threshold_pct=5
    innodb_compression_pad_pct_max=50
    loose_innodb_data_file_purge=ON
    binlog_rows_query_log_events=OFF
    innodb_stats_persistent_sample_pages=20
    innodb_ft_total_cache_size=640000000
    loose_rds_tablestat=OFF
    loose_max_statement_time=0
    innodb_flush_method=O_DIRECT
    eq_range_index_dive_limit=10
    loose_max_execution_time=0
    loose_optimizer_trace_features=greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
    connect_timeout=10
    innodb_purge_batch_size=300
    loose_rds_threads_running_high_watermark=50000
    div_precision_increment=4
    innodb_sync_array_size=1
    innodb_support_xa=ON
    innodb_stats_method=nulls_equal
    relay_log_recovery=OFF
    lock_wait_timeout=31536000
    net_read_timeout=30
    innodb_write_io_threads=4
    end_markers_in_json=OFF
    max_binlog_stmt_cache_size=18446744073709547520
    innodb_checksum_algorithm=innodb
    loose_innodb_data_file_purge_max_size=512
    query_cache_type=0
    innodb_ft_enable_diag_print=OFF
    loose_gap_lock_write_log=OFF
    innodb_ft_enable_stopword=ON
    innodb_io_capacity=20000
    slow_launch_time=2
    innodb_table_locks=ON
    innodb_stats_persistent=ON
    tmp_table_size=2097152
    disconnect_on_expired_password=ON
    loose_tokudb_auto_analyze=30
    default_storage_engine=InnoDB
    net_retry_count=10
    innodb_ft_cache_size=8000000
    binlog_cache_size=128KB
    innodb_max_dirty_pages_pct=75
    query_cache_limit=1048576
    innodb_disable_sort_file_cache=ON
    innodb_lru_scan_depth=1024
    innodb_ft_result_cache_limit=2000000000
    long_query_time=1
    interactive_timeout=7200
    innodb_read_io_threads=4
    transaction_prealloc_size=4096
    open_files_limit=65535
    innodb_open_files=3000
    max_heap_table_size=16777216
    automatic_sp_privileges=ON
    explicit_defaults_for_timestamp=false
    ft_max_word_len=84
    innodb_autoextend_increment=64
    loose_rds_max_tmp_disk_space=10737418240
    sql_mode=NO_ENGINE_SUBSTITUTION
    innodb_stats_transient_sample_pages=8
    innodb_random_read_ahead=OFF
    loose_innodb_rds_faster_ddl=OFF
    innodb_status_output=OFF
    innodb_log_compressed_pages=OFF
    slave_net_timeout=60
    delay_key_write=ON
    query_cache_wlock_invalidate=OFF
    general_log=OFF
    max_prepared_stmt_count=16382
    wait_timeout=86400
    query_cache_min_res_unit=4096
    innodb_print_all_deadlocks=OFF
    loose_thread_pool_size=1
    binlog_stmt_cache_size=32768
    transaction_isolation=READ-COMMITTED
    innodb_buffer_pool_dump_at_shutdown=OFF
    query_prealloc_size=8192
    key_cache_age_threshold=300
    transaction_alloc_block_size=8192
    optimizer_trace_limit=1
    metadata_locks_cache_size=1024
    optimizer_prune_level=1
    innodb_max_purge_lag=0
    innodb_max_dirty_pages_pct_lwm=0
    max_sp_recursion_depth=0
    innodb_status_output_locks=OFF
    updatable_views_with_limit=YES
    binlog_row_image=full
    loose_tokudb_buffer_pool_ratio=0
    innodb_change_buffer_max_size=25
    innodb_optimize_fulltext_only=OFF
    local_infile=ON
    innodb_ft_max_token_size=84
    loose_thread_pool_enabled=ON
    innodb_adaptive_hash_index=ON
    innodb_sync_spin_loops=30
    net_write_timeout=60
    flush_time=0
    lower_case_table_names=1
    character_set_filesystem=binary
    key_cache_division_limit=100
    delayed_insert_timeout=300
    preload_buffer_size=32768
    innodb_read_ahead_threshold=56
    concurrent_insert=1
    block_encryption_mode="aes-128-ecb"
    slow_query_log=ON
    net_buffer_length=16384
    query_cache_size=3145728
    innodb_buffer_pool_size=6144M
    delayed_insert_limit=100
    innodb_large_prefix=OFF
    innodb_monitor_disable=
    innodb_adaptive_flushing_lwm=10
    delayed_queue_size=1000
    innodb_thread_sleep_delay=10000
    loose_rds_set_connection_id_enabled=ON
    innodb_old_blocks_pct=37
    innodb_ft_sort_pll_degree=2
    log_slow_admin_statements=OFF
    innodb_stats_on_metadata=OFF
    stored_program_cache=256
    group_concat_max_len=10240
    innodb_sort_buffer_size=1048576
    innodb_spin_wait_delay=6
    myisam_sort_buffer_size=262144
    innodb_rollback_segments=128
    innodb_commit_concurrency=0
    innodb_concurrency_tickets=5000
    auto_increment_increment=1
    binlog_checksum=CRC32
    max_seeks_for_key=18446744073709500000
    max_length_for_sort_data=1024
    back_log=3000
    max_error_count=64
    innodb_io_capacity_max=40000
    innodb_strict_mode=OFF
    binlog_order_commits=ON
    min_examined_row_limit=0
    performance_schema=OFF
    innodb_ft_min_token_size=3
    sync_relay_log_info=10000
    innodb_stats_auto_recalc=ON
    max_connect_errors=100
    join_buffer_size=432KB
    innodb_change_buffering=all
    optimizer_trace_max_mem_size=16384
    innodb_autoinc_lock_mode=2
    innodb_rollback_on_timeout=OFF
    max_write_lock_count=102400
    master_verify_checksum=OFF
    innodb_ft_num_word_optimize=2000
    max_join_size=18446744073709551615
    loose_validate_password_length=8
    log_throttle_queries_not_using_indexes=0
    innodb_max_purge_lag_delay=0
    loose_optimizer_trace=enabled=off,one_line=off
    default_week_format=0
    innodb_cmp_per_index_enabled=OFF
    loose_rds_indexstat=OFF
    host_cache_size=643
    low_priority_updates=0
    auto_increment_offset=1
    range_alloc_block_size=4096
    ft_min_word_len=4
    sort_buffer_size=848KB
    slave_type_conversions=
    max_allowed_packet=1024M
    read_buffer_size=848KB
    thread_cache_size=256
    optimizer_trace_offset=-1
    loose_thread_pool_oversubscribe=32
    character_set_server=utf8
    innodb_adaptive_flushing=ON
    log_queries_not_using_indexes=OFF
    innodb_monitor_enable=
    innodb_flush_neighbors=0
    innodb_buffer_pool_instances=8
    EOF
    
    sleep 2
    echo "####-进行MySQL初始化-####"
    /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data
    
    sleep 1
    echo "####-修改启动脚本-####"
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    sed -i "s/basedir=/basedir=/usr/local/mysql/g" /etc/init.d/mysqld
    sed -i "s/datadir=/datadir=/data/mysql_data/g" /etc/init.d/mysqld
    
    sleep 1
    echo "####-配置环境变量-###"
    
    cat <<EOF>> /etc/profile
    export PATH=$PATH:/usr/local/mysql/bin
    export MYSQL_PS1="(u@h:p)[d]>"
    EOF
    source /etc/profile
    /etc/init.d/mysqld start
    shell 安装脚本
  • 相关阅读:
    git 学习
    ruby on rails 把阿里云上的图片资源转移到七牛云上写的一个task 文件 自动转移
    修改mysql的默认编码
    ruby on rails 安装中遇到的一些问题
    unity打包资源格式全解析
    unity打包全过程解析
    mmorpg手游中的战斗系统
    在线调试lua原型设计
    lua特性纪要
    软件开发中的哲学问题
  • 原文地址:https://www.cnblogs.com/skymyyang/p/13680357.html
Copyright © 2011-2022 走看看