centos7编译安装MySQL5.7.9

时间:2022-03-01 05:26:27

title: centos7编译安装MySQL5.7.9

date: 2016-05-12 16:20:17

tags:

Centos7编译安装mysql5.7.9

mysql5.7有更好的性能,对多核CPU和固态硬盘有着更好的优化,

更好的InnoDB引擎,更为健壮的复制功能,原生json的支持

加上一些程序的新版本也偏向优先支持MySQL5.7,所以我们有必要安装配置一下mysql5.7

平台:Centos 7

版本:Centos 5.7.9

一 准备工作

安装依赖

$ yum -y install gcc gcc-c++ ncurses ncurses-devel cmake

如果是centos6并已经装好cmake,需要检查一下cmake的版本,编译MySQL5.7需要的最低版本为2.8

下载源码包

$ wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12.tar.gz

$ wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.12.tar.gz

编译MySQL5.7需要boost支持,如果事先没有装好boost,就下载下面这个。

添加MySQL用户

$ sudo useradd -M -s /sbin/nologin     mysql

安装

解压然后进入

$ tar -xf mysql-boost-5.7.12.tar.gz && cd mysql-5.7.12

预编译

$ cmake /
-DCMAKE_INSTALL_PREFIX=/home/nick/mysql /
-DMYSQL_UNIX_ADDR=/home/nick/mysql/mysql.sock /
-DDEFAULT_CHARSET=utf8 /
-DDEFAULT_COLLATION=utf8_general_ci /
-DWITH_INNOBASE_STORAGE_ENGINE=1 /
-DWITH_ARCHIVE_STORAGE_ENGINE=1 /
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 /
-DMYSQL_DATADIR=/home/nick/mysql/data /
-DMYSQL_TCP_PORT=3306
-DWITH_BOOST=boost

编译安装,最好开个screen

$ make && make install

这一步时间会比较长,你可以出去吃个饭或者睡一觉,如果在上班的话,那就先忙其他的,两三个个小时后看看。

完成之后

 $ cd /home/nick/mysql && mkdir etc tmp var log data

 #复制一份配置文件,有需要的话进去修改一下
cp support-files/my-default.cnf etc/my.cnf

我看了下,默认的话其实并没有什么配置,所以可以参照下面的

port = 3306
socket = /home/nick/mysql/mysql.sock
default-character-set = utf8mb4 [mysqld]
port = 3306
socket = /home/nick/mysql/mysql.sock basedir = /home/nick/mysql
datadir = /home/nick/mysql/data
pid-file = /home/nick/mysql/log/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1 init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4 #skip-name-resolve
#skip-networking
back_log = 300 max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 1M
binlog_cache_size = 1M
max_heap_table_size = 2M
tmp_table_size = 4M read_buffer_size = 1M
read_rnd_buffer_size = 2M
sort_buffer_size = 2M
join_buffer_size = 2M
key_buffer_size = 1M thread_cache_size = 8 query_cache_type = 1
query_cache_size = 2M
query_cache_limit = 1M ft_min_word_len = 4 log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30 log_error = /home/nick/mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /home/nick/mysql/log/mysql-slow.log performance_schema = 0
explicit_defaults_for_timestamp #lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 16M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 1M
innodb_log_file_size = 8M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1 interactive_timeout = 28800
wait_timeout = 28800 [mysqldump]
quick
max_allowed_packet = 8M

然后初始化mysql

$ /home/nick/mysql/bin/mysqld --initialize-insecure --user=nick --basedir=/home/nick/mysql --datadir=/home/nick/mysql/data

之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃

“–initialize”会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure”不会生成密码

–datadir目标目录下不能有数据文件

注意 这次安装的MySQL5.7.12是没有生产 ~/.mysql_secret文件的,同时也没有密码 输入用户名就可以直接登录。

启动MySQL

$ /home/nick/mysql/bin/mysqld --defaults-file=/home/nick/mysql/etc/my.cnf

登录后修改root密码

mysql5.7以后mysql.user表就没有了password字段

update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
plush privileges;

使用supervisor来管理MySQL

supervisor的部署就不多说了,直接看配置

[program:mysql]
command=/home/nick/mysql/bin/mysqld --defaults-file=/home/nick/mysql/etc/my.cnf
directory=/home/nick/mysql
user=nick

MySQL5.7就此安装完毕