一. 安装环境准备

  1. 系统信息
    CentOS release 6.5 (Final)
    2.6.32-431.el6.x86_64
  2. 目录创建
    程序目录:/usr/local/mysql_5.7.22/
    数据目录:/var/lib/mysql_5.7.22/data/
    命令:
    mkdir /var/lib/mysql_5.7.22/{data,logs,tmp} -p
    chown -R mysql:mysql  /var/lib/mysql_5.7.22
  3. 安装依赖
    yum -y install numactl.x86_64
    不然初始化报错:
    error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
  4. 准备my.cnf配置文件
    参数详细解释参考:https://blog.csdn.net/gzt19881123/article/details/52594783
    log_timestamps=SYSTEM
    explicit_defaults_for_timestamp = 1
    user = mysql
    server-id = 57
    port = 3306
    basedir = /usr/local/mysql_5.7.22/
    datadir = /var/lib/mysql_5.7.22/data/
    tmpdir = /var/lib/mysql_5.7.22/tmp/
    socket = /var/lib/mysql_5.7.22/tmp/mysql.sock
    skip_name_resolve = 1
    slave_skip_errors = 1062
    character-set-server = utf8mb4
    collation-server = utf8mb4_general_ci
    init_connect = 'SET NAMES utf8mb4'
    lower_case_table_names = 1
    max_connections = 1000
    max_connect_errors = 99999
    max_allowed_packet = 128M
    interactive_timeout = 1800
    wait_timeout = 1800
    tmp_table_size = 134217728
    max_heap_table_size = 134217728
    query_cache_size = 0
    query_cache_type = 0
    read_buffer_size = 131072
    read_rnd_buffer_size = 262144
    sort_buffer_size = 2097152
    binlog_cache_size = 524288
    back_log = 130
    log_error = /var/lib/mysql_5.7.22/logs/error.log
    slow_query_log = on
    slow_query_log_file = /var/lib/mysql_5.7.22/logs/mysqld-slow.log
    log_queries_not_using_indexes = 1
    log_throttle_queries_not_using_indexes = 5
    long_query_time = 3
    min_examined_row_limit = 100
    expire_logs_days = 5
    log-bin = mysql-bin
    binlog_format = MIXED
    log_slave_updates
    innodb_buffer_pool_size = 6G
    innodb_log_buffer_size = 16777216
    innodb_flush_method = O_DIRECT
    innodb_write_io_threads = 2
    innodb_read_io_threads = 6
    #innodb_log_group_home_dir = /data/logs/redolog/
    #innodb_undo_directory = /data/logs/undolog/
    innodb_log_files_in_group = 3
    innodb_log_file_size = 1024M
    #innodb_undo_log_truncate = 1
    #innodb_undo_tablespaces = 3
    #innodb_undo_logs = 128
    innodb_print_all_deadlocks = 1
    [mysqldump]
    quick
    max_allowed_packet = 128M
    [mysql]
    no-auto-rehash
    [myisamchk]
    key_buffer_size = 20M
    sort_buffer_size = 256k
    read_buffer = 2M
    write_buffer = 2M
    [mysqld_safe]
    open-files-limit = 28192
    log-error=/var/lib/mysql_5.7.22/logs/mysqld.log
    pid-file=/var/lib/mysql_5.7.22/tmp/mysqld.pid

    二. 安装初始化

  5. 下载解压:
    https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
    tar -xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    mv mysql-5.7.22-linux-glibc2.12-x86_64/  mysql_5.7.22
  6. 初始化:
    /usr/local/mysql_5.7.22/bin/mysqld --defaults-file=/usr/local/mysql_5.7.22/my.cnf --basedir=/usr/local/mysql_5.7.22/ --datadir=/var/lib/mysql_5.7.22/data/ --initialize
    查看日志less /var/lib/mysql_5.7.22/logs/error.log,看是否有报错
  7. 启动mysql
    /usr/local/mysql_5.7.22/bin/mysqld_safe --defaults-file=/usr/local/mysql_5.7.22/my.cnf &
    这个时候会报错显示没有/var/lib/mysql_5.7.22/logs/mysqld.log这个日志文件,手动创建,重新启动就不会报错
    touch /var/lib/mysql_5.7.22/logs/mysqld.log
    启动完成后,查看日志文件是否有报错
    ps waux |grep mysql 查看进程是否启动
  8. 登录mysql
    grep password /var/lib/mysql_5.7.22/logs/error.log 查看原始密码
    类似这样root@localhost: yn.X?gQ!d2?3
    /usr/local/mysql_5.7.22/bin/mysql -uroot -p'yn.X?gQ!d2?3' -S /var/lib/mysql_5.7.22/tmp/mysql.sock
  9. 登录mysql 后修改密码
    set password=password(‘123456’);