首页 > 数据库 > MySQL > MySQL5.7.21 源码安装详细步骤
http://blog.csdn.net/hwh1231/article/details/71426844
MySQL5.7.21 源码安装详细步骤
版本选择:
1、 生产环境如何选择MySQL版本
1. 选择社区版的稳定GA版本
2. 可以选择5.1或5.5.互联网公司主流5.5, 其次是5.1和5.6
3. 选择发布后6个月以上的GA版
4. 要选择前后几个月没有打的BUG修复的版本,而不是大量修复BUG的几种版本
5. 最好选择向后较长时间没有更新发布的版本
6. 考虑开发人员开发程序使用的版本是否兼容你选的版本
7. 企业非核心业务采用新版本的数据库GA版本软件
8. 作为内部开发测试数据库环境,跑大概3-6个月时间
9. 向DBA高手请教,或者在技术氛围好的群里和大家一起交流,使用真正高手用过的好用的GA版本产品
10. 经过上述工序后,若没有重要的功能BUG或性能瓶颈,则可以开始考虑作为任何业务数据服务的后端数据库软件。
2、 MySql数据库的多种安装方法
1. yum/rpm安装
2. 常规方式编译安装
3. 采用cmake方式编译安装
4. 二进制方式免编译安装
MySQL5.7.18 源码安装详细步骤
一:操作系统环境和目录结构
[root@tqsrv121 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
[root@tqsrv121 ~]# 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% /u02
注意,在安装操作系统时,把cmake装上。
yum install centos-release-scl -y
yum install devtoolset-4-gcc-c++
devtoolset-4-gcc -y
yum install cmake git -y
yum install ncurses-devel openssl-devel
bison -y
二、获取MySQL5.7.18源码安装包,并上传至服务器。
MySQL官网下载地址:https://dev.mysql.com/downloads/mysql/
下载版本:mysql-boost-5.7.21.tar.gz 此版本带有boost。
Select Operating System: 选择 “Source Code”
Select OS Version: 选择 “Generic Linux (Architecture Independent)”
注:AliSQL-github: https://github.com/alibaba/AliSQL
三、创建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软件目录: /u02/mysql3307/5.7/install
mysql数据目录: /u02/mysql3307/5.7/data
mysql日志目录: /u02/mysql3307/5.7/log/
mysql日志目录: /u02/mysql3307/5.7/log/bin_log
mysql配置文件目录: /u02/mysql3307/5.7/config
mysql临时目录: /u02/mysql3307/5.7/tmp
[root@mysql3 ~]# mkdir -p /u02/mysql3307/5.7/install
[root@mysql3 ~]# mkdir -p /u02/mysql3307/5.7/data
[root@mysql3 ~]# mkdir -p /u02/mysql3307/5.7/log/bin_log
[root@mysql3 ~]# mkdir -p /u02/mysql3307/5.7/config
[root@mysql3 ~]# mkdir -p /u02/mysql3307/5.7/tmp
[root@mysql3 u02]# pwd
/u02
[root@mysql3 u02]# chown -R mysql:mysql mysql3307/
四、解压MySQL并编译并安装
1.解压MySQL安装文件:
[root@mysql3 software]# pwd
/u02/software/
[root@mysql3 software]# ls
mysql-boost-5.7.21.tar.gz
[root@mysql3 software]# tar -xvf mysql-boost-5.7.21.tar.gz
2.进入解压后的软件目录进行CMake,CMake的目的是生成makefile文件,为下一步编译做准备
如果之前编译不成功,请执行以下命令:
make clean
rm CMakeCache.txt
进入解压后的目录:cd /data/mysql/src/mysql-5.7.18
编译前要确保磁盘空间是足够的,至少6G以上吧,db初始化时 再给5个G吧。
后面我在做db初始化时,空间不够,命令直接跳出,没任何提示,搞了半天才知道时空间的原因。
进入解压后的目录:cd /data/mysql/src/mysql-5.7.21
cmake . -DCMAKE_INSTALL_PREFIX=/u02/mysql3307/5.7/install \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=complex \
-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 5.7 steven.hua' \
-DWITH_READLINE=ON \
-DWITH_BOOST=/u02/software/mysql-5.7.21/boost \
-DSYSCONFDIR=/u02/mysql3307/5.7/config \
-DMYSQL_DATADIR=/u02/mysql3307/5.7/data \
-DMYSQL_UNIX_ADDR=/u02/mysql3307/5.7/data/mysql.sock
WITH_EXTRA_CHARSETS
注意:关于cmake编译的参数可以到官网学习。https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
-D 相当于就是定义, -D 可以理解为告诉cmake 后边我要定义一些参数了, 你每定义一个就在前边加上-D就是了
3.编译并安装
cd /data/mysql/src/mysql-5.7.21
make -j 4 & make install
(注意:这步需要1.5个小时左右,请耐心等待)
4.配置my.cnf文件
vi /u02/mysql3307/5.7/config/my.cnf
[client]
port=3306
socket=/u02/mysql3307/5.7/data/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/u02/mysql3307/5.7/data/mysql.sock
pid-file=/u02/mysql3307/5.7/data/mysql.pid
basedir=//u02/mysql3307/5.7/installdir
datadir=/u02/mysql3307/5.7/data
tmpdir=/u02/mysql3307/5.7/tmpdir
log_error=/u02/mysql3307/5.7/log/mysql2.err
server-id = 1
log_bin =/u02/mysql3307/5.7/log/bin_log/binlog
general_log_file=/u02/mysql3306/5.7/log/general_log
general_log = 1
slow_query_log = ON
long_query_time = 2
slow_query_log_file =/u02/mysql3307/5.7/log/query_log
log_queries_not_using_indexes = ON
5.初始化数据库
cd /u02/mysql3307/5.7/install/bin
./mysqld --initialize --user=mysql --basedir= --datadir=
如果OS上安装过其它版本的mysql,最好添加参数–no-defaults,进行初始化(不使用别人的cnf配置文件)。并且,切记要放在参数的首位!否则,不产生作用。
./mysqld --no-defaults --initialize --user=mysql --basedir= --datadir=
[root@tqsrv122 bin]# ./mysqld --no-defaults --initialize --user=mysql --basedir=/u02/mysql3307/5.7/install --datadir=/u02/mysql3307/5.7/data
2018-03-07T07:23:38.584709Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-07T07:23:40.654332Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-03-07T07:23:40.878625Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-07T07:23:40.994385Z 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: 75ed60bb-21d8-11e8-b1da-00163e2cd3a8.
2018-03-07T07:23:40.996637Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-03-07T07:23:40.997386Z 1 [Note] A temporary password is generated for root@localhost: :GgrlfFs-8ok
6.安装ssl,可指定文件生成路径,默认为DATA里面
cd /u02/mysql3307/5.7/install/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'
生成的文件在/u02/mysql3307/5.7/data目录下
7.启动数据库
./mysqld_safe --defaults-file=/u02/mysql3307/5.7/config/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.21源码安装完成!
9.错误整理:
1)5.7编译cmake要求版本最低为2.8
2)之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃。
3)初始化密码: mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。
shell> cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2015-04-22 22:13:23
?G5W&tz1z.cN
修改默认密码
shell> bin/mysqladmin -h localhost -u root password '123@qwe' -p'?G5W&tz1z.cN'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
4)另外mysql5.7的mysql.user表结构被修改
修改mysql.user方式修改密码
mysql> update mysql.user set authentication_string=password('123qwe') where user='svoid' and Host = 'localhost';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
5)磁盘空间满了也会报“collect2: error: ld returned 1 exit status”错误
Linking CXX executable CMakeFiles/CMakeRelink.dir/mysql_embedded
Linking CXX executable CMakeFiles/CMakeRelink.dir/mysqltest_embedded
collect2: error: ld returned 1 exit status
make[2]: *** [libmysqld/examples/CMakeFiles/CMakeRelink.dir/mysqltest_embedded] Error 1
make[1]: *** [libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/preinstall] Error 2
make: *** [preinstall] Error 2
===============================
第二次做参数
cmake . -DCMAKE_INSTALL_PREFIX=/usr/server/mysql3307/5.7/install \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=complex \
-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 5.7 steven.hua' \
-DWITH_READLINE=ON \
-DWITH_BOOST=/usr/server/soft/mysql-5.7.21/boost \
-DSYSCONFDIR=/usr/server/mysql3307/5.7/config \
-DMYSQL_DATADIR=/usr/server/mysql3307/5.7/data \
-DMYSQL_UNIX_ADDR=/usr/server/mysql3307/5.7/data/mysql.sock
[client]
port=3307
socket=/usr/server/mysql3307/5.7/data/mysql.sock
[mysqld]
port=3307
bind_address=10.26.47.25
user=mysql
server-id=1
character_set_server=utf8
collation_server=utf8_general_ci
max_connections=800
max_connect_errors=100000
#MySQL file path
socket=/usr/server/mysql3307/5.7/data/mysql.sock
pid-file=/usr/server/mysql3307/5.7/data/mysql.pid
basedir=/usr/server/mysql3307/5.7/install
datadir=/usr/server/mysql3307/5.7/data
tmpdir=/usr/server/mysql3307/5.7/tmp
log_error=/usr/server/mysql3307/5.7/log/mysql2.err
#MySQL bin_log
log_bin =/usr/server/mysql3307/5.7/data/bin_log/binlog
sync_binlog=1
innodb_support_xa=1
binlog_format=ROW #5.7.7 default
general_log_file=/usr/server/mysql3306/5.7/log/generallog
general_log = 1
#slow_query_log = ON
#long_query_time = 2
#slow_query_log_file =/usr/server/mysql3307/5.7/log/querylog
#log_queries_not_using_indexes = ON
#explicit_defaults_for_timestamp=OFF #default off
#innodb memory setting
innodb_buffer_pool_size = 1G
innodb_buffer_pool_instances=2
innodb_log_buffer_size = 8M
#innodb datafile setting
innodb_file_per_table = true
innodb_data_file_path = ibdata1:100M:autoextend
innodb_flush_method = O_DIRECT
#innodb redo log
innodb_log_file_size = 1G
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 1
#innodb io setting -plugin options
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_purge_threads=4
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
#innodb_max_dirty_pages_pct=75
#innodb recovery when initialize
#innodb_force_recovery=0 #default 0 start srv after complete recovery
#innodb shutdown type
#innodb_fast_shutdown=0 #default 0 full purge and merge insert buffer
# replication master
#server-id=1
#log_bin=/usr/server/mysql3307/5.7/data/bin_log/binlog
#sync_binlog=1
#innodb_flush_log_at_trx_commit=1
# replication slave
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/807718/viewspace-2151553/ ,如需转载,请注明出处,否则将追究法律责任。