wait_timeout = 86400
lock_wait_timeout = 50
max_allowed_packet = 256M
max_connect_errors = 2000
max_connections = 2000
max_user_connections = 2000
join_buffer_size = 4M
sort_buffer_size = 4M
#table_definition_cache = 5000
#table_open_cache = 8000
#table_open_cache_instances = 4
#thread_cache_size = 9
#thread_stack = 256K
tmp_table_size = 32M
max_heap_table_size = 32M
binlog_cache_size = 1M
############# SAFETY ##############
#local_infile = OFF
#{$validate_password_enable}plugin-load = validate_password.so
#skip_name_resolve = ON
#sql_mode = STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY
############# LOGGING #############
#general_log = 0
log_queries_not_using_indexes = OFF
log_throttle_queries_not_using_indexes = 0
log_slow_admin_statements = ON
log_error_verbosity = 3
long_query_time = 3
slow_query_log = ON
log_timestamps = SYSTE
############# REPLICATION #############
#binlog_checksum = CRC32
#master_verify_checksum = ON
#slave_sql_verify_checksum = ON
binlog_format = ROW
binlog_rows_query_log_events = ON
expire_logs_days = 3
max_binlog_size = 256M
enforce_gtid_consistency = ON
gtid_mode = ON
log_slave_updates = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
server_id=000001
#skip_slave_start = ON
#slave_net_timeout = 4
sync_binlog = 100
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
slave_parallel_workers = 4
slave_parallel_type = LOGICAL_CLOCK
relay_log_recovery = ON
slave_skip_errors = all
[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/var/mysqld.pid
[client]
#default-character-set=utf8
[mysql]
default-character-set=utf8
EOF
sed -i "s/server_id=000001/server_id=$server_id/g" /etc/my.cnf
cd /apps/mysql/bin
mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/mysql/data
mysql_ssl_rsa_setup --datadir=/data/mysql/data
mysqld_safe > /dev/null 2>&1 &
sleep 15
ln -s /apps/mysql/bin/msql /usr/bin
passwd1=`cat /data/mysql/log/error.log | grep password | awk -F "root@localhost:" '{print $2}'| awk -F " " '{print $1}'`
echo "initial password:"$passwd1
passwd2="'test123'"
passwd3="test123"
echo "<---------------modify passwd------------------>"
mysql -uroot -h127.0.0.1 -p${passwd1} --connect-expired-password -e "alter user 'root'@'localhost' identified by ${passwd2}"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "grant all privileges on *.* to root@'%' identified by ${passwd2};"
echo "The root password has been changed:"$passwd3
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "grant replication slave,replication client on *.* to replic_user identified by 'test123';"
echo "The cluster user name have been created:replic_user"
echo "The cluster password have been created:test123"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "FLUSH PRIVILEGES;"
echo "<---------------end------------------>"
备注脚本内容可以根据自己的数据库版本进行调整,此脚本已在安装生产环境使用过,数据库的参数,可以根据自己的服务器配置进行调整 。
推荐阅读
- go语言操作PostgreSQL数据库
- CENTOS自动巡检服务器性能指标
- Index MySQL查询合理使用索引:别让你的数据库负重前行
- 数据库:SQLServer分页查询整理
- 5大常用MySQL客户端工具,入门数据库必备收藏
- 面试被问:JDBC底层是如何连接数据库的?
- centos7 shell脚本一键安装nginx
- 生产环境下shell脚本:Mysql数据库备份和Mysql主从同步监控
- Mysql数据库实现主从同步,看这一篇就够了
- 如何在CentOS/RHEL系统中使用带VLAN标记的网卡