首页 > 代码库 > 在CentOS6.7操作系统上编译安装mysql-5.6.31

在CentOS6.7操作系统上编译安装mysql-5.6.31

功能概述:

   由于在centos 6.7下通过yum安装的mysql是5.1版本的,不满足需求,因此经常性需要编译安装mysql服务等。

一、安装mysql

 1、安装前提

     1)安装编译mysql代码所依赖的包

  [root@bqe6tewv41kx ~]# yum -y install make gcc-c++ cmake bison-devel  ncurses-devel
   2)下载mysql-5.5.20源码包

  [root@bqe6tewv41kx ~]#http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.31.tar.gz

   3)创建mysql用户及mysql数据目录

  [root@bqe6tewv41kx ~]#useradd -r -s /sbin/nologin mysql

  [root@bqe6tewv41kx ~]#mkdir -p /blog/data

  [root@bqe6tewv41kx ~]#chown -R mysql.mysql /blog/data

 2、编译安装mysql

      [root@bqe6tewv41kx ~]#tar xf mysql-5.6.31.tar.gz

  [root@bqe6tewv41kx ~]#cd mysql-5.6.31

  [root@bqe6tewv41kx mysql-5.6.31]# cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/blog/data \     -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=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

  [root@bqe6tewv41kx mysql-5.6.31]#make && make install

  (常见的编译参数见mysql官网:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html)

二、配置mysql服务

  [root@bqe6tewv41kx ~]#chown -R mysql:mysql /usr/local/mysql

     1)初始化配置

  [root@bqe6tewv41kx mysql-5.6.31]#cd /usr/local/mysql

  [root@bqe6tewv41kx mysql]#scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/blog/data --user=mysql

    160902 16:56:14 [Note] /usr/local/mysq//bin/mysqld (mysqld 5.5.50) starting as process 18740 ...
      OK
      Filling help tables...
      160902 16:56:14 [Note] /usr/local/mysq//bin/mysqld (mysqld 5.5.50) starting as process 18748 ...
      OK
     (看见这两个OK,然后进入cd /blog/data目录看看是不是有数据库在里面)

     2)配置mysql启动服务

      [root@bqe6tewv41kx mysq]# cp support-files/mysql.server /etc/init.d/mysqld
      [root@bqe6tewv41kx mysql]#chmod +x /etc/init.d/mysqld

   3) 配置/etc/my.cnf

  [root@bqe6tewv41kx mysql]# vim /etc/my.cnf

  [root@bqe6tewv41kx mysql]# vim /etc/my.cnf

    [mysqld]
      datadir=/blog/data
      socket=/tmp/mysql.sock
      user=mysql
      innodb_file_per_table=1
      # Disabling symbolic-links is recommended to prevent assorted security risks
      symbolic-links=0

      [mysqld_safe]
      log-error=/var/log/mysqld.log
      pid-file=/var/run/mysqld/mysqld.pid
      [root@bqe6tewv41kx mysql]#ln -sv /tmp/mysql.sock /var/lib/mysql/mysql.sock

      [root@bqe6tewv41kx mysql]#service mysqld start

       4) 配置PATH变量及创建mysql密码

       [root@bqe6tewv41kx mysq]# vim /etc/profile.d/mysql.sh

    PATH=/usr/local/mysq/bin:$PATH
    export PATH

        [root@bqe6tewv41kx mysql]#source /etc/profile.d/mysql.sh

        修改mysql服务器的root密码

         [root@bqe6tewv41kx mysql]#mysql -uroot

         mysql> SET PASSWORD = PASSWORD(‘123456‘);

         mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘10.2.18.%‘ IDENTIFIED BY ‘Lsf123‘ WITH GRANT OPTION;
        5)配置iptables防火墙服务,放行3306端口

   [root@bqe6tewv41kx mysql]#iptables -I INPUT -m state --state NEW -m tcp -p tcp -dport 3306 -j ACCEPT  

         [root@bqe6tewv41kx mysql]#service iptables save

      [root@bqe6tewv41kx mysql]#service iptables restart

   

在CentOS6.7操作系统上编译安装mysql-5.6.31