安装初始依赖
[root@cloud-master ~]# yum -y install gcc gcc-c++ make wget openssl-devel
[root@cloud-master ~]# cd /usr/src/
下载boost包
[root@cloud-master src]# wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
[root@cloud-master src]# tar xf boost_1_59_0.tar.gz
[root@cloud-master src]# cp -r boost_1_59_0/ /usr/local/boost
下载MySQL-boost版并解压
[root@cloud-master src]# wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.29.tar.gz
[root@cloud-master src]# tar zxf mysql-boost-5.7.29.tar.gz
安装MySQL
预备Mysql需要的依赖和目录
[root@cloud-master src]# useradd -M -s /sbin/nologin mysql
[root@cloud-master ~]# cd /usr/src/mysql-5.7.29/
[root@cloud-master mysql-5.7.29]# mkdir -p /usr/local/mysql_57/{data,logs,conf}
[root@cloud-master mysql-5.7.29]# chown -R mysql.mysql /usr/local/mysql_57/
[root@cloud-master mysql-5.7.29]# yum -y install ncurses-devel
cmake预编译
注:更多预编译配置参数请参考mysql官方文档:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options
-DCMAKE_INSTALL_PREFIX:mysql安装目录
-DMYSQL_DATADIR:数据存放目录
-DWITH_BOOST:boost源码路径
-DSYSCONFDIR:my.cnf配置文件目录
-DDEFAULT_CHARSET:数据库默认字符编码
-DDEFAULT_COLLATION:默认排序规则
-DENABLED_LOCAL_INFILE:允许从本文件导入数据
-DEXTRA_CHARSETS:安装所有字符集
[root@cloud-master mysql-5.7.29]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql_57 -DMYSQL_DATADIR=/usr/local/mysql_57/data -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/usr/local/mysql_57/conf -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all
编译,-j参数根据实际机器配置进行调整,否则可能会出现内存不足
[root@cloud-master mysql-5.7.29]# make -j 4 && make install
[root@cloud-master mysql-5.7.29]# cd /usr/local/mysql_57
编辑MySQL配置文件
[root@cloud-master mysql_57]# vim conf/my.cnf
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql_57/data
skip-external-locking
performance_schema_max_table_instances=400
log-error=/usr/local/mysql_57/logs/error.log
pid-file=/usr/local/mysql_57/logs/mysql.pid
table_definition_cache=400
table_open_cache=256
key_buffer_size = 16M
max_allowed_packet = 100G
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
explicit_defaults_for_timestamp = true
#skip-networking
#最大连接数
max_connections = 1024
#在mysql暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中
back_log = 128
#服务器在关闭它前在一个交互连接上等待行动的秒数。
interactive_timeout = 7200
max_connect_errors = 100
open_files_limit = 65535
log_bin=mysql_bin
binlog-format=Row
server-id=1
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_data_home_dir = /usr/local/mysql_57/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql_57/data
innodb_thread_concurrency = 2
innodb_buffer_pool_size = 16M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
explicit_defaults_for_timestamp=true
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
初始化
[root@cloud-master mysql_57]# /usr/local/mysql_57/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql_57 --datadir=/usr/local/mysql_57/data
2020-04-18T08:25:18.121036Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-18T08:25:21.299121Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-04-18T08:25:21.769547Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-18T08:25:21.969330Z 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: 2532159d-814e-11ea-b67b-000c2920881d.
2020-04-18T08:25:21.970079Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-04-18T08:25:22.297193Z 0 [Warning] CA certificate ca.pem is self signed.
2020-04-18T08:25:22.317917Z 1 [Note] A temporary password is generated for root@localhost: mkpy8q%!X&U+
启动前修改:
[root@cloud-master mysql_57]# sed -i "s#\(^lockdir=\).*#\1'/usr/local/mysql_57/logs'#" support-files/mysql.server
[root@cloud-master mysql_57]# rm -rf /etc/my.cnf
启动MySQL
[root@cloud-master mysql_57]# ./support-files/mysql.server start
第一次使用需修改密码才能进行操作
[root@cloud-master mysql_57]# ./bin/mysql -uroot -p'mkpy8q%!X&U+'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29-log
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password=password('lolicp.com_Test');
Query OK, 0 rows affected, 1 warning (0.00 sec)
遇到的问题
1.内存不足,加大服务器内存或加swap
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report
2.默认文件未删除/etc/my.cnf
[root@cloud-master bin]# ../support-files/mysql.server start
Starting MySQL.2020-04-18T09:18:17.712873Z mysqld_safe error: log-error /var/log/mariadb set to '/var/log/mariadb/mariadb.log', however f
ERROR! The server quit without updating PID file (/usr/local/mysql_57/logs/mysql.pid).