一、所需软件
软件名称版本下载地址当前环境管理员账号/密码
mysql
5.6
yum安装
CentOS6.7系统
linuxidc/linuxidc
二、安装说明
数据库所在目录/database/mysql新建目录mysql
sock文件路径
/var/lib/mysql/mysql.sock
自动生成
配置文件路径
/etc/my.cnf
慢查询日志路径
/var/log/mysql/mysql_slow_query.log
新建mysql日志目录
错误日志路径
/var/log/mysql/mysqld.log
pid文件
/var/run/mysqld/mysqld.pid
自动生成
binlog日志文件
/database/mysql-bin/mysql_bin*.log
新建目录mysql-bin
三、安装
1、下载yum源。
官网地址:
centos7系统:
wget
centos6系统:
wget
2、安装rpmrpm -Uvh mysql57-community-release-el6-7.noarch.rpm
3、修改yum源配置vim /etc/yum.repos.d/mysql-community.repo
安装mysql5.6操作
1、将enabled=1更改为enabled=0 2、将enabled=0更改为enabled=1如图:
4、安装mysqlyum install mysql-community-server
5、替换配置文件主库配置文件:
[mysqld]
user=mysql
datadir=/database/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#slow_queries
slow_query_log_file = /var/log/mysql/mysql_slow_query.log
long_query_time=1
slow_query_log=1
#binlog
server-id=77
log_bin=/database/mysql-bin/mysql_bin
binlog_format=mixed
expire_logs_days=7
#innodb
innodb_buffer_pool_size=104G
innodb_log_file_size=512M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
innodb_file_io_threads=4
innodb_flush_method=O_DIRECT
innodb_io_capacity=2000
innodb_io_capacity_max=6000
innodb_lru_scan_depth=2000
innodb_thread_concurrency = 0
#cache
##内部内存临时表的最大值
tmp_table_size=2G
character-set-server=utf8
collation-server=utf8_general_ci
##即跳过外部锁定
skip-external-locking
##MySQL能暂存的连接数量(根据实际设置)
back_log=1024
##指定索引缓冲区的大小,只对MyISAM表起作用,这里写上也没有关系
key_buffer_size=1024M
##这条指令限定用于每个数据库线程的栈大小
thread_stack=256k
##当一个查询不断地扫描某一个表,MySQL会为它分配一段内存缓冲区
read_buffer_size=8M
##线程缓存
thread_cache_size=64
##查询缓存大小
query_cache_size=128M
##内部内存临时表的最大值,每个线程都要分配
max_heap_table_size=256M
##将查询结果放入查询缓存中
query_cache_type=1
##代表在事务过程中容纳二进制日志SQL语句的缓存大小
binlog_cache_size = 2M
##同样是缓存表大小
table_open_cache=128
##缓存线程
thread_cache=1024
wait_timeout=18000
##表和表联接的缓冲区的大小
join_buffer_size = 1024M
##是一个connection级参数,在每个connection第一次需要使用这个buffer的时候,一次性分配设置的内存
sort_buffer_size=8M
##随机读取数据缓冲区使用内存
read_rnd_buffer_size = 8M
#connect
##是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码
max-connect-errors=100000
##连接数
max-connections=3000
##开启查询缓存
explicit_defaults_for_timestamp=true
##mysql服务器能够工作在不同的模式下,并能针对不同的客户端以不同的方式应用这些模式
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
[mysqld_safe]
log-error=/var/log/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
mysql主库配置文件
从库配置文件:
# For advice on how to change settings please see
#
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove lead/ing # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
user=mysql
datadir=/database/mysql
socket=/var/lib/mysql/mysql.sock
server-id=214 #以ip为mysql的server-id
skip-name-resolve
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#slow_queries
slow_query_log_file = /var/log/mysql/mysql_slow_query.log
long_query_time=1
slow_query_log=1