mysql5.6 centos编译部署

准备工作

创建用户

useradd mysql

删除老版本

rpm -qa |grep mysql
rep -e mysql包

重命名默认的mysql配置文件

mv /etc/my.cnf /etc/my.cnf.old

下载mysql

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz

安装依赖

yum -y install make gcc-c++ cmake bison-devel ncurses-devel

安装配置

解压

tar -xf mysql-5.6.35.tar.gz
cd mysql-5.6.35

编译安装

cmake \
-DCMAKE_INSTALL_PREFIX=/home/heron/mysql-3306 \
-DMYSQL_DATADIR=/home/heron/mysql/data \
-DMYSQL_UNIX_ADDR=/home/heron/mysql-3306/mysql-3306.sock \
-DSYSCONFDIR=/home/heron/mysql-3306/etc \
-DDEFAULT_CHARSET=utf8 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

make -j8 && make -j8 install

配置启动

cd /home/heron/mysql-3306/
mkdir logs etc tmp var

初始化

vim /home/heron/mysql-3306/etc/my.cnf

这个配置有关于复制相关的配置,不用复制的话,请忽略,需要从库只需修改配置server-id并打开read

[client]
port    = 3309
socket  = /home/xiaohe/mysql-3309/mysql.sock

[mysql]
prompt="\u@XH-TEST-01:3309>"
no-auto-rehash
[mysqld]
user    = nobody
port    = 3309
socket  = /home/xiaohe/mysql-3309/mysql.sock
basedir = /home/xiaohe/mysql-3309
datadir = /home/xiaohe/mysql-3309/data
pid-file  = /home/xiaohe/mysql-3309/mysql.pid
log-error = /home/xiaohe/mysql-3309/logs/mysql.err
tmpdir = /home/xiaohe/mysql-3309/tmp/
slave-load-tmpdir = /home/xiaohe/mysql-3309/tmp/
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit    = 65535
back_log = 1024
max_connections = 3000
max_connect_errors = 100000
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 300
query_cache_size = 0
query_cache_type = 0
tmp_table_size = 96M
max_heap_table_size = 96M
slow_query_log = 1
slow_query_log_file = /home/xiaohe/mysql-3309/logs/slow.log
long_query_time = 0.1
server-id = 11
read-only
#忽略记录,建议不忽略
#binlog-ignore-db=mysql
#binlog-ignore-db=information_schema
#binlog-ignore-db=performance_schema
#忽略复制,建议开启
#replicate-ignore-db=mysql
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
#忽略表复制
#replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%
log-bin = /home/xiaohe/mysql-3309/data/mysql-bin
#允许的服务器
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1024M
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_repair_threads = 1
myisam_recover
lock_wait_timeout = 300
explicit_defaults_for_timestamp = 1
metadata_locks_hash_instances = 64
innodb_thread_concurrency = 0
transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 5734M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_data_home_dir  = /home/xiaohe/mysql-3309/data/
innodb_log_group_home_dir = /home/xiaohe/mysql-3309/data/
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_open_files = 384
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 0
innodb_online_alter_log_max_size = 4G
innodb_status_file = 1
#performance_schema
performance_schema = 1
performance_schema_instrument = '%=on'
#innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"
[mysqldump]
quick
max_allowed_packet  = 64M

初始化

/home/heron/mysql-3306/scripts/mysql_install_db

/home/heron/mysql-3307/scripts/mysql_install_db

如果报错

FATAL ERROR: please install the following Perl modules before executing /home/heron/mysql-3306/scripts/mysql_install_db:

安装下面的包

yum install -y perl-Module-Install.noarch

启动

/home/heron/mysql-3306/bin/mysqld_safe &
/home/heron/mysql-3307/bin/mysqld_safe &

建议使用supervisor管理

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


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

默认没有密码 设置root密码

SET PASSWORD = PASSWORD('123456');

安装告一段落

主从同步

创建同步账号

登录主库

GRANT RELOAD, REPLICATION SLAVE, SUPER ON . TO 'slave'@'127.0.0.1' IDENTIFIED BY '123456';

flush privileges;

查看主库状态

root@localhost 19:25: [(none)]> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin.000004 | 1638 | | | c0d14e5b-f8e7-11e6-a9ed-001c42f6626e:1-7 |
+------------------+----------+--------------+------------------+------------------------------------------+

登录从库

CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=1638, MASTER_CONNECT_RETRY=5, MASTER_HEARTBEAT_PERIOD=3;

开启slave

start slave

查看slave

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

有这两项就说明成功了。

至此 MySQL5.6的安装、配置、启动、主从就完成了。

posted @ 2017-06-12 14:32  boy215  阅读(199)  评论(0编辑  收藏  举报