MySQL 5.7 编译安装

SOSO
2021-09-28 / 0 评论 / 98 阅读 / 正在检测是否收录...

MySQL 5.7 编译安装

安装依赖

yum install ncurses ncurses-devel -y
[root@localhost]# groupadd mysql
[root@localhost]# useradd -s /sbin/nologin -M -g mysql mysql
[root@localhost soft]# tar zxf mysql-boost-5.7.34.tar.gz 
[root@localhost soft]# cd mysql-5.7.34/
[root@localhost mysql-5.7.34]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 \
-DWITH_BOOST=/opt/soft/mysql-5.7.34/boost
  • my.cnf

    [client]
    #password   = your_password
    port        = 3306
    socket      = /tmp/mysql.sock
    
    [mysqld]
    port        = 3306
    socket      = /tmp/mysql.sock
    datadir = /usr/local/mysql/data
    skip-external-locking
    key_buffer_size = 16M
    max_allowed_packet = 1M
    table_open_cache = 64
    sort_buffer_size = 512K
    net_buffer_length = 8K
    read_buffer_size = 256K
    read_rnd_buffer_size = 512K
    myisam_sort_buffer_size = 8M
    thread_cache_size = 8
    query_cache_size = 8M
    tmp_table_size = 16M
    performance_schema_max_table_instances = 500
    
    explicit_defaults_for_timestamp = true
    #skip-networking
    max_connections = 500
    max_connect_errors = 100
    open_files_limit = 65535
    
    log-bin=mysql-bin
    binlog_format=mixed
    server-id   = 1
    expire_logs_days = 10
    early-plugin-load = ""
    
    default_storage_engine = InnoDB
    innodb_file_per_table = 1
    innodb_data_home_dir = /usr/local/mysql/data
    innodb_data_file_path = ibdata1:10M:autoextend
    innodb_log_group_home_dir = /usr/local/mysql/data
    innodb_buffer_pool_size = 16M
    innodb_log_file_size = 5M
    innodb_log_buffer_size = 8M
    innodb_flush_log_at_trx_commit = 1
    innodb_lock_wait_timeout = 50
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [mysql]
    no-auto-rehash
    
    [myisamchk]
    key_buffer_size = 20M
    sort_buffer_size = 20M
    read_buffer_size = 2M
    write_buffer_size = 2M
    
    [mysqlhotcopy]
    interactive-timeout
    
  • 初始化数据库

    --initialize-insecure 密码为空
    --initialize 生成默认密码
    [root@local]# chown -R mysql.mysql /usr/local/mysql/data
    [root@local]# /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
    [root@local]# chgrp -R mysql /usr/local/mysql/.
  • 设置开机启动

    [root@local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    [root@local]# chmod 755 /etc/init.d/mysqld
    
    [root@local]# ln -sf /usr/local/mysql/bin/mysql /usr/bin/mysql
    [root@local]# ln -sf /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
    [root@local]# ln -sf /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
    [root@local]# ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
    [root@local]# ln -sf /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck
  • 设置root密码

    [root@local]# mysql 
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${DB_Root_Password}');
  • 内存小于2G

    key_buffer_size = 32M
    table_open_cache = 128
    sort_buffer_size = 768K
    read_buffer_size = 768K
    myisam_sort_buffer_size = 8M
    thread_cache_size = 16
    query_cache_size = 16M
    tmp_table_size = 32M
    innodb_buffer_pool_size = 128M
    innodb_log_file_size = 32M
    performance_schema_max_table_instances = 1000
  • 内存 2G-4G

    key_buffer_size = 64M
    table_open_cache = 256
    sort_buffer_size = 1M
    read_buffer_size = 1M
    myisam_sort_buffer_size = 16M
    thread_cache_size = 32
    query_cache_size = 32M
    tmp_table_size = 64M
    innodb_buffer_pool_size = 256M
    innodb_log_file_size = 64M
    performance_schema_max_table_instances = 2000
  • 内存 4G-8G

    key_buffer_size = 128M
    table_open_cache = 512
    sort_buffer_size = 2M
    read_buffer_size = 2M
    myisam_sort_buffer_size = 32M
    thread_cache_size = 64
    query_cache_size = 64M
    tmp_table_size = 64M
    innodb_buffer_pool_size = 512M
    innodb_log_file_size = 128M
    performance_schema_max_table_instances = 4000
  • 内存 8G-16G

    key_buffer_size = 256M
    table_open_cache = 1024
    sort_buffer_size = 4M
    read_buffer_size = 4M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 128
    query_cache_size = 128M
    tmp_table_size = 128M
    innodb_buffer_pool_size = 1024M
    innodb_log_file_size = 256M
    performance_schema_max_table_instances = 6000

    -内存 16G-32G

    key_buffer_size = 512M
    table_open_cache = 2048
    sort_buffer_size = 8M
    read_buffer_size = 8M
    myisam_sort_buffer_size = 128M
    thread_cache_size = 256
    query_cache_size = 256M
    tmp_table_size = 256M
    innodb_buffer_pool_size = 2048M
    innodb_log_file_size = 512M
    performance_schema_max_table_instances = 8000
  • 内存 > 32g

    key_buffer_size = 1024M
    table_open_cache = 4096
    sort_buffer_size = 16M
    read_buffer_size = 16M
    myisam_sort_buffer_size = 256M
    thread_cache_size = 512
    query_cache_size = 512M
    tmp_table_size = 512M
    innodb_buffer_pool_size = 4096M
    innodb_log_file_size = 1024M
    performance_schema_max_table_instances = 10000
0

评论 (0)

取消