docker centos7 源码安装MySQL-5.7

  1. 增加用户和目录
     

[root@96bc8c1a98e4 /]# groupadd mysql

[root@96bc8c1a98e4 /]# useradd -g mysql mysql

[root@96bc8c1a98e4 /]# passwd mysql

 

[root@96bc8c1a98e4 /]# mkdir -p /usr/local/mysql

[root@96bc8c1a98e4 /]# chown -R mysql:mysql /usr/local/mysql

[root@96bc8c1a98e4 /]# mkdir -p /data/mysql

[root@96bc8c1a98e4 /]# chown -R mysql:mysql  /data/mysql

 

[root@96bc8c1a98e4 /]# su - mysql

[root@96bc8c1a98e4 /]# cd ~

 

  1. 下载MySQL源码和安装必要工具包

    这里下载最新版本
    MySQL(5.7)源码:
    [mysql@96bc8c1a98e4 ~]# wget
    http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-5.7.9-1.el7.src.rpm

    下载MySQL编译依赖的boost包:

[mysql@96bc8c1a98e4 ~]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download -O boost_1_59_0.tar.gz
 

安装必要工具包:

[mysql@96bc8c1a98e4 ~]# sudo yum -y install make gcc-c++ autoconfm4cmake bison-devel  ncurses-devel
 

  1. 编译安装MySQL
     

[mysql@96bc8c1a98e4 ~]# tar -zxvf boost_1_59_0.tar.gz

[mysql@96bc8c1a98e4 ~]# rpm -i mysql-community-5.7.9-1.el7.src.rpm

[mysql@96bc8c1a98e4 ~]$ cd rpmbuild/SOURCES/

[mysql@96bc8c1a98e4 SOURCES]$ tar -zxvf mysql-5.7.9.tar.gz

[mysql@96bc8c1a98e4 SOURCES]$ cd mysql-5.7.9

 

[mysql@96bc8c1a98e4 mysql-5.7.9]$ cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

 -DMYSQL_DATADIR=/data/mysql  \

 -DWITH_INNOBASE_STORAGE_ENGINE=1 \

 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

 -DMYSQL_USER=mysql  \

 -DDEFAULT_CHARSET=utf8 \

 -DDEFAULT_COLLATION=utf8_general_ci \

 -DDOWNLOAD_BOOST=1 \

 -DWITH_BOOST=/home/mysql/boost_1_59_0

 

 

注意:这里指定之前下载的并解压后boost目录:

 -DDOWNLOAD_BOOST=1 \

 -DWITH_BOOST=/home/mysql/boost_1_59_0

 

因为依赖boost,若不指定会报:

-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_59_0

 

参数见参考(2

 

配置完后,编译、安装:

[mysql@96bc8c1a98e4 mysql-5.7.9]$ make
[mysql@96bc8c1a98e4 mysql-5.7.9]$ make
install
 

  1. 数据库参数设置
    /usr/local/mysql/support-files/my-default.cnff复制到 /etc/my.cnf

并在my.cnf中指定数据目录:

 

[mysqld]
basedir=/usr/local/mysql

datadir=/data/mysql

 

 

启动:

/usr/local/mysql/bin/mysqld_safe &

 

启动完之后升级初始化:

/usr/local/mysql/bin/mysql_upgrade

 

修改root用户密码

[mysql@eadf5d52fd36 bin]$ ./mysql -uroot -p

Enter password: 

 

mysql> use mysql

 

mysql> update user set authentication_string=PASSWORD("你的新密码") where User='root';

Query OK, 0 rows affected, 1 warning (0.01 sec)

Rows matched: 1  Changed: 0  Warnings: 1

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

 

停止:
/usr/local/mysql/bin/mysqladmin shutdown -uroot  -p

Root

也可以使用:

/usr/local/mysql/bin/mysqld stop

 

.  参考

  1. http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
  2. http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

你可能感兴趣的:(MySQL,docker)