1. 程式人生 > >二進制安裝mysql 5.7.22

二進制安裝mysql 5.7.22

exe base ESS eas quic 進程 查看進程 logs arc

一. 安裝環境準備

  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’);

二進制安裝mysql 5.7.22