MySQL5.7源码安装

环境

系统:CentOS 6.6
软件:mysql-boost-5.7.21.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-boost-5.7.21.tar.gz
    # cd mysql-5.7.21
    
    # cmake \
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DMYSQL_DATADIR=/data/mysql \
    -DSYSCONFDIR=/etc \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
    -DMYSQL_TCP_PORT=3306 \
    -DENABLED_LOCAL_INFILE=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DEXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_BOOST=boost/boost_1_59_0
    
    # 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
    
    [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
    # bin/mysqld --initialize --user=mysql --basedir=/usr/local/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
    

报错修改

  • 修改临时密码

    # vim /etc/my.cnf
    [mysqld]中添加 skip-grant-tables
    
    # mysql 
    mysql> use mysql;
    mysql> update user set authentication_string=password('123456') where user='root';
    mysql> flush privileges;
    mysql> exit
    
    将最开始修改的配置文件my.cnf中的skip-grant-tables删除
    
  • 报错

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement;
    
    mysql> SET PASSWORD = PASSWORD('123456');
    
  • 授权

    mysql> use mysql;
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
    mysql> flush privileges;
    

你可能感兴趣的:(MySQL5.7源码安装)