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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在CentOS6.7操作系统上编译安装mysql-5.6.31相关的知识,希望对你有一定的参考价值。

功能概述:

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

一、安装mysql

 1、安装前提

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

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

  [[email protected] ~]#http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.31.tar.gz

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

  [[email protected] ~]#useradd -r -s /sbin/nologin mysql

  [[email protected] ~]#mkdir -p /blog/data

  [[email protected] ~]#chown -R mysql.mysql /blog/data

 2、编译安装mysql

      [[email protected] ~]#tar xf mysql-5.6.31.tar.gz

  [[email protected] ~]#cd mysql-5.6.31

   [[email protected] 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

  [[email protected] mysql-5.6.31]#make && make install

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

二、配置mysql服务

  [[email protected] ~]#chown -R mysql:mysql /usr/local/mysql

     1)初始化配置

  [[email protected] mysql-5.6.31]#cd /usr/local/mysql

  [[email protected] 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启动服务

      [[email protected] mysq]# cp support-files/mysql.server /etc/init.d/mysqld
      [[email protected] mysql]#chmod +x /etc/init.d/mysqld

   3) 配置/etc/my.cnf

  [[email protected] mysql]# vim /etc/my.cnf

  [[email protected] 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
      [[email protected] mysql]#ln -sv /tmp/mysql.sock /var/lib/mysql/mysql.sock

      [[email protected] mysql]#service mysqld start

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

       [[email protected] mysq]# vim /etc/profile.d/mysql.sh

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

        [[email protected] mysql]#source /etc/profile.d/mysql.sh

        修改mysql服务器的root密码

         [[email protected] 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端口

   [[email protected] mysql]#iptables -I INPUT -m state --state NEW -m tcp -p tcp -dport 3306 -j ACCEPT  

         [[email protected] mysql]#service iptables save

      [[email protected] mysql]#service iptables restart

   

以上是关于在CentOS6.7操作系统上编译安装mysql-5.6.31的主要内容,如果未能解决你的问题,请参考以下文章

在CentOS上编译安装MySQL+安装问题解决+安全优化

CentOS 7 上编译安装MySQL 5.6.23

在centos6.9上编译安装LAMP并搭建个人博客

centos6.7下 编译安装MySQL5.7

CentOS6上编译安装ZABBIX 3.0

在windows 上编译部署Rap2