题外话
作为Mysql DBA,我们平时必须要熟练的一个最最基础的技能,即安装部署Mysql实例,所以本文分享一个快速安装部署Mysql实例的方法。
一、环境介质准备
Mysql安装包准备
Mysql官方网站下载社区版二进制安装包:
https://downloads.mysql.com/archives/community/
PS:可以根据自己的情况,自行选择需要的版本。
服务器准备
我这里使用的是centos 7.x,此方法适用于任何其他linux版本。
配置文件my.cnf准备
一般情况下,用其他安装方式(YUM,自行编译等),会自动生成默认配置文件,但不建议那样做,因为根据服务器各方面的配置不同,Mysql的配置参数也要做相应的调整,才能最优。
下面贴出我的配置文件:(仅供参考,因为测试好多参数是随意配置的)
#**************MySQL5.7***************
[client]
default-character-set=utf8
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /d/mysqldata/mysql3306/sock/mysql.sock
basedir = /d/mysqlbase/mysql3306
datadir = /d/mysqldata/mysql3306/mydata
tmpdir = /d/mysqldata/mysql3306/tmpdir
pid-file= /d/mysqldata/mysql3306/sock/mysql.pid
transaction-isolation=Read-Committed
secure_file_priv=
local-infile=1
skip-symbolic-links
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
lower_case_table_names=1
explicit_defaults_for_timestamp
#sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
sql_mode=''
skip-name-resolve
back_log=1000
max_connections=1000
max_user_connections=7900
thread_cache_size=128
max_connect_errors=99999
wait_timeout=172800
interactive_timeout=172800
net_buffer_length=32K
max_allowed_packet=1G
max_heap_table_size=1G
tmp_table_size=2M
query_cache_type=2
query_cache_size=0
#query_cache_limit=1M
performance_schema=1
event-scheduler=1
#
disabled_storage_engines='BLACKHOLE,FEDERATED'
group_concat_max_len=1048576
lock_wait_timeout=300
max_seeks_for_key=10000
### logs
general_log_file=/d/mysqldata/mysql3306/log/general.log
log-error=/d/mysqldata/mysql3306/log/error.log
log_error_verbosity=3
log_timestamps=SYSTEM
slow_query_log
slow_query_log_file=/d/mysqldata/mysql3306/log/slow-query.log
long_query_time=0.3
log_slow_admin_statements=1
#log_slow_slave_statements=1
##log_queries_not_using_indexes
log-bin-index=/d/mysqldata/mysql3306/binlog/mysql-bin.index
log-bin=/d/mysqldata/mysql3306/binlog/mysql-bin
#
relay-log-index=/d/mysqldata/mysql3306/relaylog/mysql-relay-bin.index
relay-log=/d/mysqldata/mysql3306/relaylog/mysql-relay-bin
#
binlog_cache_size=256K
max_binlog_size=512M
#
binlog-format=ROW
binlog_row_image=minimal #can only use higher than 5.7.14
#binlog_group_commit_sync_delay=5 #can only use higher than 5.7.17
#binlog_group_commit_sync_no_delay_count=64
sync_binlog=1
expire_logs_days=10
### replication
server_id=92
log_slave_updates=1
log_bin_trust_function_creators=1
#auto_increment_increment=1
#auto_increment_offset=1
allow_suspicious_udfs
sysdate-is-now
gtid-mode=ON
enforce-gtid-consistency
#
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=1
#
plugin_load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_master_enabled=1
rpl_semi_sync_slave_enabled=1
rpl_semi_sync_master_timeout=10000
rpl_semi_sync_master_wait_no_slave=0
#
slave_parallel_workers=4
slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=1
slave_pending_jobs_size_max=1G
#buffer
read_buffer_size=466K
read_rnd_buffer_size=466K
sort_buffer_size=932K
join_buffer_size=233K
### innnodb
innodb_buffer_pool_size=1638M
innodb_buffer_pool_instances=8
innodb_max_dirty_pages_pct=85
innodb_sort_buffer_size=16M
large-pages
#
innodb_data_home_dir=/d/mysqldata/mysql3306/innodb_ts
innodb_data_file_path=ibdata1:128M:autoextend
innodb_autoextend_increment=128
innodb_open_files=7168
innodb_file_per_table
##innodb temp
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
#
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_log_file_size=256M
innodb_log_files_in_group=3
innodb_log_group_home_dir=/d/mysqldata/mysql3306/innodb_log
innodb_adaptive_flushing_lwm=30
#
innodb_read_io_threads=16
innodb_write_io_threads=8
innodb_io_capacity=1000 #for ssd
innodb_flush_neighbors=0 #for ssd
innodb_flush_method=O_DIRECT
innodb_lru_scan_depth=256
innodb_purge_threads=8
#
innodb_thread_concurrency=0
innodb_concurrency_tickets=1024
#
innodb_lock_wait_timeout=300
#
#innodb_rollback_on_timeout=1
#innodb_force_recovery=0
[mysqldump]
quick
max_allowed_packet = 1G
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
二、安装部署
安装目录创建
mkdir /d/mysqlbase/ ---程序目录
mkdir /d/mysqldata/mysql3306/ ---数据目录
把上面下载的Mysql安装包解压到/d/mysqlbase/,并重命名:
tar -zxvf mysql-5.7.30-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.30-linux-glibc2.5-x86_64 mysql3306
创建各配置目录:(对应上面配置文件)
cd /data/mysqldata/mysql3306/
mkdir {binlog,innodb_log,innodb_ts,log,mydata,sock,relaylog,tmpdir}
新增配置文件:(对应上面配置文件)
vim my.cnf
ls /d/mysqldata/mysql3306/ |grep my.cnf
创建mysql用户并授权:
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /d/mysqldata//*
chown -R mysql:mysql /data/mysqlbase/*
初始化
初始化:
./mysqld --defaults-file=/dad/mysqldata/mysql3306/my.cnf --initialize-insecure --user=mysql ----root密码为空
查看日志:
[Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
只有一个Warning信息,没用异常,说明初始化成功。
三、启动测试
用配置文件启动Mysql实例
/d/mysqlbase/mysql3306/bin/mysqld_safe --defaults-file=/d/mysqldata/mysql3306/my.cnf.3306 2>&1 > /dev/null &
登陆Mysql实例
/d/mysqlbase/mysql3306/bin/mysql -uroot -p -S /d/mysqldata/mysql3306/sock/mysql.sock
PS:由于前面初始化时加了参数–initialize-insecure,root密码为空,所以这里可以用root直接登陆,然后创建用户就好。
三、总结
Mysql实例已经安装部署完成,是不是特别简单快捷。同样的方法即可完成多实例的安装部署(只需修改相应的端口等信息)
当然,Mysql安装部署是很基础的技能,还有很多种其他部署方式,大家有兴趣可以自行对比研究。
哎哟,不错噢! - - - - - - 欢迎指出有误的地方以及补充更好的方法