@cdmonkey
2017-03-28T16:11:24.000000Z
字数 3919
阅读 1048
数据库
https://my.oschina.net/kcw/blog/812802
http://blog.csdn.net/u012453679/article/details/60480682
解压二进制安装包
[root@PBSZBXPROXYDB tools]# tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /opt/
[root@PBSZBXPROXYDB tools]# ln -s /opt/mysql-5.7.17-linux-glibc2.5-x86_64/ /usr/local/mysql
# Config PATH
[root@PBSZBXPROXYDB ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
[root@PBSZBXPROXYDB ~]# source ~/.bash_profile
创建用户:
[root@PBSZBXPROXYDB ~]# groupadd mysql
[root@PBSZBXPROXYDB ~]# useradd -r -g mysql -s /bin/false mysql
安装依赖包:
yum -y install libaio libaio-devel
复制启动脚本。
注意:我们不使用这个安装包里自带的服务脚本,而是使用下面提供的脚本,因而该步骤可不执行。
[root@PBSZBXPROXYDB ~]# cd /opt/mysql/
[root@PBSZBXPROXYDB mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@PBSZBXPROXYDB mysql]# chmod +x /etc/init.d/mysqld
创建数据目录并进行授权。
[root@PBSZBXPROXYDB ~]# mkdir -p /data/mysql/mysql3306/{data,logs,tmp}
[root@PBSZBXPROXYDB ~]# chown -R mysql:mysql /usr/local/mysql/
[root@PBSZBXPROXYDB ~]# chown -R mysql:mysql /data/mysql/mysql3306/
上传配置文件,该配置文件是事先准备好的(请注意配置文件的位置):
[root@PBSZBXPROXYDB ~]# vim /data/mysql/mysql3306/mysql3306.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt='(product)\u@\h [\d]>'
no-auto-rehash
[mysqld]
# Misc
user = mysql
basedir = /opt/mysql
datadir = /data/mysql/mysql3306/data
port = 3306
socket = /tmp/mysql.sock
event_scheduler = 0
# Tmp
tmpdir=/data/mysql/mysql3306/tmp
lower_case_table_names = 1
# Timeout
interactive_timeout = 300
wait_timeout = 300
# Character Set
character-set-server = utf8
open_files_limit = 65535
max_connections = 2048
max_connect_errors = 100000
skip-name-resolve = 1
# Logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
#explicit_defaults_for_timestamp=1
# Binlog
binlog_format = row
server-id = 2493306
log-bin = /data/mysql/mysql3306/logs/mysql-bin
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
sync_binlog = 1
innodb_flush_log_at_trx_commit = 1
expire_logs_days = 10
binlog_checksum = NONE # for GR
# Relay log
relay-log = /data/mysql/mysql3306/logs/relay-bin
skip_slave_start = 1
max_relay_log_size = 1G
relay_log_purge = 0
relay_log_recovery = 1
log_slave_updates = 1
#slave-skip-errors=1032,1053,1062
# Replication
gtid_mode = ON
enforce_gtid_consistency = ON
#new feture
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 2
relay_log_recovery = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
# Buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
# Myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
# Innodb
innodb_buffer_pool_size = 3G
innodb_buffer_pool_instances = 4
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 64M
innodb_log_file_size = 500M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
[mysqld_safe]
nice=-19
open-files-limit=65535
数据库初始化:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/mysql3306.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data
注意:使用
--initialize-insecure
参数的目的是不初始化root
用户密码,因而不会生成一个随机密码。
创建启停止脚本:
[root@PBSZBXPROXYDB ~]# vim /data/mysql/mysql3306/start.sh
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/mysql3306.cnf &
[root@PBSZBXPROXYDB ~]# vim /data/mysql/mysql3306/stop.sh
/usr/local/mysql/bin/mysqladmin -uroot -psuixingpay123 shutdown
注意:上面的
root
用户的密码要依据实际情况进行修改。
启动数据库:
[root@PBSZBXPROXYDB ~]# sh /data/mysql/mysql3306/start.sh
服务启动后就能够直接登录了(因为未初始化root
的密码,因而无需输入密码,直接登录):
[root@PBSZBXPROXYDB ~]# mysql -uroot