当前位置 主页 > 服务器问题 > Linux/apache问题 >

    Linux下Centos7安装Mysql5.7.19的详细教程

    栏目:Linux/apache问题 时间:2019-10-17 12:14

    1.下载mysql

    网址: https://dev.mysql.com/downloads/mysql/

    2.选择源码包,通用版点击下载

    直接下载就可以了,不用登录

    3.解压编译

    tar -zxvf mysql-5.7.19.tar.gz
    cd mysql-5.7.19.tar.gz

    创建数据目录  mkdir -p /data/mysql

    先用cmake编译,没有这个命令需要先yum安装

    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/  #这个是编译安装之后的mysql目录所在地,可自行更改
    -DMYSQL_DATADIR=/data/mysql/    #这个指向数据目录
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
    -DSYSCONFDIR=/usr/local/mysql-5.7/conf/
    -DWITH_MYISAM_STORAGE_ENGINE=1
    -DWITH_INNOBASE_STORAGE_ENGINE=1
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1
    -DWITH_ARCHIVE_STORAGE_ENGINE=1
    -DWITH_MEMORY_STORAGE_ENGINE=1
    -DWITH_READLINE=1
    -DMYSQL_TCP_PORT=3306
    -DENABLED_LOCAL_INFILE=1
    -DDEFAULT_CHARSET=utf8
    -DDEFAULT_COLLATION=utf8_general_ci
    -DMYSQL_USER=mysql
    -DWITH_SSL=system
    -DWITH_ZLIB=system -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost #从MySQL 5.7.5开始Boost库是必需安装的

    编译之后make && make install  漫长的等待....之后就安装完成了

    安装完成之后路径/usr/local/ 下面会有一个目录 mysql,这个目录就是我编译安装设置的路径-

    DCMAKE_INSTALL_PREFIX=/usr/local/mysql/

    一般为了安全起见,我们都会创建一个mysql用户和mysql组,执行以下命令

    #添加用户组
    groupadd mysql
    #添加用户mysql 到用户组mysql
    useradd
    -g mysql mysql

    给予mysql权限

    chown -R mysql:mysql mysql
    #添加用户组
    groupadd mysql
    #添加用户mysql 到用户组mysql
    useradd -g mysql mysql

    给予mysql权限

    chown -R mysql:mysql mysql

    4.接下来配置启动向,设置开机启动

    配置/ect/my.cnf,如果没有my.cnf可自行新建添加 ,  仅供参考

    [client]
    ort = 3306
    ocket = /tmp/mysql.sock
    default-character-set = utf8mb4
    [mysqld]
    ort = 3306
    ocket = /tmp/mysql.sock
    asedir = /usr/local/mysql
    datadir = /data/mysql
    id-file = /data/mysql/mysql.pid
    user = mysql
    ind-address = 0.0.0.0
    erver-id = 1
    init-connect = 'SET NAMES utf8mb4'
    character-set-server = utf8mb4
    #skip-name-resolve
    #skip-networking
    ack_log = 300
    max_connections = 1000
    max_connect_errors = 6000
    open_files_limit = 65535
    table_open_cache = 128
    max_allowed_packet = 4M
    inlog_cache_size = 1M
    max_heap_table_size = 8M
    tmp_table_size = 16M
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    ort_buffer_size = 8M
    join_buffer_size = 8M
    key_buffer_size = 4M
    thread_cache_size = 8
    query_cache_type = 1
    query_cache_size = 8M
    query_cache_limit = 2M
    ft_min_word_len = 4
    log_bin = mysql-bi
    inlog_format = mixed
    expire_logs_days = 30
    log_error = /data/mysql/mysql-error.log
    low_query_log = 1
    long_query_time = 1
    low_query_log_file = /data/mysql/mysql-slow.log
    erformance_schema = 0
    explicit_defaults_for_timestam
    #lower_case_table_names = 1
    kip-external-locking
    default_storage_engine = InnoDB
    #default-storage-engine = MyISAM
    innodb_file_per_table = 1
    innodb_open_files = 500
    innodb_buffer_pool_size = 64M
    innodb_write_io_threads = 4
    innodb_read_io_threads = 4
    innodb_thread_concurrency = 0
    innodb_purge_threads = 1
    innodb_flush_log_at_trx_commit = 2
    innodb_log_buffer_size = 2M
    innodb_log_file_size = 32M
    innodb_log_files_in_group = 3
    innodb_max_dirty_pages_pct = 90
    innodb_lock_wait_timeout = 120
    ulk_insert_buffer_size = 8M
    myisam_sort_buffer_size = 8M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    interactive_timeout = 28800
    wait_timeout = 28800
    [mysqldump]
    quick
    max_allowed_packet = 16M
    [myisamchk]
    key_buffer_size = 8M
    ort_buffer_size = 8M
    read_buffer = 4M
    write_buffer = 4M