MySQL5.7.18 源码安装详细步骤



MySQL5.7.18 源码安装详细步骤


一:操作系统环境和目录结构


[root@mysql3 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
[root@mysql3 ~]# 
[root@mysql3 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        16G  5.4G  9.6G  36% /
tmpfs           932M     0  932M   0% /dev/shm
/dev/sda1        79G   56M   75G   1% /data



注意,在安装操作系统时,把cmake装上。

二、获取MySQL5.7.18源码安装包,并上传至服务器。


MySQL官网下载地址:https://dev.mysql.com/downloads/mysql/

下载版本:mysql-boost-5.7.18.tar.gz 此版本带有boost。


三、创建MySQL用户以及MySQL数据库目录划分


创建MySQL用户:

groupadd -g 701 mysql

useradd -M -g mysql -u 1101 -s /sbin/nologin  mysql  #建立mysql账号,-M不建立家目录,-s自动以shell为/sbin/nologin账号不能登录


(如若已存在MySQL用户,在确定不影响其他功能的情况下,可将之删除,并重建)


MySQL数据库目录划分:

mysql软件目录: /data/mysql/installdir
mysql数据目录:/data/mysql/datadir/3306/data
mysql日志目录:/data/mysql/logdir/3306/{bin_log,general_log,error_log,query_log}

[root@mysql3 ~]# mkdir -p /data/mysql/installdir
[root@mysql3 ~]# mkdir -p /data/mysql/datadir/3306/data
[root@mysql3 ~]# mkdir -p /data/mysql/logdir/3306/{bin_log,general_log,error_log,query_log}

 [root@mysql3 data]# pwd
/data
[root@mysql3 data]# chown -R mysql:mysql mysql/


四、解压MySQL并编译并安装


1.解压MySQL安装文件:

[root@mysql3 src]# pwd
/data/mysql/src
[root@mysql3 src]# ls
mysql-boost-5.7.18.tar.gz
[root@mysql3 src]# tar -xvf mysql-boost-5.7.18.tar.gz


2.进入解压后的软件目录进行CMake,CMake的目的是生成makefile文件,为下一步编译做准备
如果之前编译不成功,请执行以下命令:
make clean
rm CMakeCache.txt


进入解压后的目录:cd /data/mysql/src/mysql-5.7.18

cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql/installdir \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='MySQL wenyi.huang' \
-DWITH_READLINE=ON \
-DWITH_BOOST=/data/mysql/src/mysql-5.7.18/boost \
-DSYSCONFDIR=/data/mysql/datadir/3306/data \
-DMYSQL_UNIX_ADDR=/data/mysql/datadir/3306/data/mysql.sock


[root@mysql3 mysql-5.7.18]# cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql/installdir  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DENABLED_LOCAL_INFILE=ON  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_FEDERATED_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1  -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1  -DWITH_PARTITION_STORAGE_ENGINE=1  -DWITH_PERFSCHEMA_STORAGE_ENGINE=1  -DCOMPILATION_COMMENT='MySQL wenyi.huang'  -DWITH_READLINE=ON  -DWITH_BOOST=/data/mysql/src/mysql-5.7.18/boost  -DSYSCONFDIR=/data/mysql/datadir/3306/data  -DMYSQL_UNIX_ADDR=/data/mysql/datadir/3306/data/mysql.sock


  
  注意:关于cmake编译的参数可以到官网学习。https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html



3.编译并安装

cd /data/mysql/src/mysql-5.7.18

make & make install

(注意:这步需要1.5个小时左右,请耐心等待)

4.配置my.cnf文件

vi /etc/my.cnf
[client]
port=3306
socket=/data/mysql/datadir/3306/data/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/data/mysql/datadir/3306/data/mysql.sock
pid-file=/data/mysql/datadir/3306/data/mysql.pid
basedir=/data/mysql/installdir
datadir=/data/mysql/datadir/3306/data
tmpdir=/data/mysql/tmpdir

log_error=/data/mysql/logdir/3306/error_log/mysql3.err

server-id = 1
log_bin = /data/mysql/logdir/3306/bin_log/binlog

general_log_file=/data/mysql/logdir/3306/general_log
general_log      = 1

slow_query_log = ON
long_query_time = 2
slow_query_log_file = /data/mysql/logdir/3306/query_log
log_queries_not_using_indexes = ON

5.初始化数据库

cd /data/mysql/installdir/bin

./mysqld --initialize --user=mysql --basedir=/data/mysql/installdir --datadir=/data/mysql/datadir/3306/data

[root@mysql3 bin]# ./mysqld --initialize --user=mysql --basedir=/data/mysql/installdir --datadir=/data/mysql/datadir/3306/data
2017-05-08T13:53:02.019530Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-05-08T13:53:03.084456Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-05-08T13:53:03.192605Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-05-08T13:53:03.335050Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a7cd6864-33f5-11e7-b4e5-000c29d7ab18.
2017-05-08T13:53:03.338753Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-05-08T13:53:03.341861Z 1 [Note] A temporary password is generated for root@localhost: hTdE.-th:5.g

6.安装ssl,可指定文件生成路径,默认为DATA里面

 cd /data/mysql/installdir/bin
 
./mysql_ssl_rsa_setup

[root@mysql3 bin]# ./mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
.........................+++
..................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
..............................................................................+++
...............................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
........+++
................+++
writing new private key to 'client-key.pem'

生成的文件在/data/mysql/datadir/3306/data目录下


7.启动数据库

./mysqld_safe --defaults-file=/etc/my.cnf &

或 
cp /data/mysql/installdir/support-files/mysql.server /etc/init.d/mysqld

/etc/init.d/mysqld start

8.登陆客户端,建库建表建用户。

./mysql -uroot -p   hTdE.-th:5.g

alter user 'root'@'localhost' identified by 'root@20170508';

CREATE DATABASE HWYDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
use HWYDB;
create table hwy( nid int not null auto_increment primary key, name varchar(32) not null, email varchar(64) not null, extra text, unique ix_name (name) );

grant SELECT,INSERT,UPDATE,DELETE on HWYDB.* to 'dbadmin'@'172.16.115.%' identified by 'dbadmin@20170508';

至此,MySQL5.7.18源码安装完成!


你可能感兴趣的:(MySQL)