欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL5.6源码安装

程序员文章站 2022-05-26 23:39:58
...

环境

系统:CentOS 6.6
软件:mysql-5.6.36.tar.gz

mysql安装

  • 下载源码包
    地址:https://downloads.mysql.com/archives/community/

  • 创建mysql用户

    # useradd mysql
    
  • 安装依赖包

    # yum -y install autoconf automake cmake gcc-c++ libgcrypt libtool libxml2 ncurses-devel zlib
    
  • 编译安装

    # tar -xzvf mysql-5.6.36.tar.gz
    # cd mysql-5.6.36
    
    # cmake \
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DENABLED_LOCAL_INFILE=1 \
    -DMYSQL_DATADIR=/data/mysql/data \
    -DSYSCONFDIR=/etc \
    -DWITH_PARTITION_STORAGE_ENGINE=1
    
    # make
    # make install
    
  • 配置环境变量

    # vim /etc/profile
    export PATH=/usr/local/mysql/bin:$PATH
    
    # source /etc/profile
    

mysql配置

  • 配置my.cnf

    # vim /etc/my.cnf
    [mysqld_safe]
    log-error=/data/mysql/log/mysql.err
    
    [mysqld]
    datadir=/data/mysql/data
    tmpdir=/data/mysql/tmp
    socket=/var/lib/mysql/mysql.sock
    user=mysql
    
    character_set_server=utf8
    
    default-storage-engine=INNODB
    innodb_buffer_pool_size=1G
    
    slow_query_log=1
    slow_query_log_file=/data/mysql/log/mysql.slow
    long_query_time=2
    
    server_id=1
    log-bin=/data/mysql/log-bin/log-bin
    binlog_format=row
    
    max_connections=1000
    
    [client]
    socket=/var/lib/mysql/mysql.sock
    
  • 创建所需目录

    # mkdir -p /data/mysql/data
    # mkdir -p /data/mysql/log
    # mkdir -p /data/mysql/log-bin
    # mkdir -p /data/mysql/tmp
    
    # mkdir /var/lib/mysql
    
  • 创建所需文件

    # touch /data/mysql/log/mysql.err
    
  • 改变属主和属组

    # chown -R mysql:mysql /data/mysql
    # chown -R mysql:mysql /var/lib/mysql
    # chown -R mysql:mysql /usr/local/mysql
    
  • 执行初始化配置脚本

    # cd /usr/local/mysql
    # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data
    

mysql启动

  • 启动

    # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    # chkconfig --add mysqld
    # chkconfig mysqld on
    # service mysqld restart
    
  • 运行安全配置向导

    # ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
    # mysql_secure_installation
    Enter current password for root (enter for none):
    新安装mysql无root密码,按Enter即可
    Set root password? [Y/n] Y
    Remove anonymous users? [Y/n] Y
    Disallow root login remotely? [Y/n] n
    Remove test database and access to it? [Y/n] Y
    Reload privilege tables now? [Y/n] Y