【mysql】Linux centos 7.5 + mysql5.7二进制自动安装脚本(包括自动修改root密码)
程序员文章站
2024-03-14 14:55:46
...
mysql5.7二进制自动安装脚本(包括自动修改root密码)
1、脚本内容
vi /home/meng/deploy_mysql57.sh
#!/bin/bash
#
#首先将压缩文件和配置文件(mysql57.cnf)放到/home/meng目录
#软件目录:/usr/local/mysql
#数据目录:/data/mysql_data
#deploy_mysql57.sh
#
#相关目录
MYSQL_FILE='/home/meng'
MYSQL_HOME='/usr/local'
MYSQL_DATA='/data/mysql_data'
MYSQL_TAR='/home/meng/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz'
MYSQL_UNZIP_FILE='mysql-5.7.23-linux-glibc2.12-x86_64'
TIME=`date +%Y%m%d%H%M%S`
#安装环境准备
find / -name "mysql" -exec rm -rf {} \; >/dev/null 2>&1
id mysql
if [ "0" == "$?" ];then
echo "mysql用户存在,删除mysql用户和组"
pid=`pidof mysqld`
kill -9 $pid >/dev/null 2>&1
/usr/sbin/userdel -r mysql > /dev/null 2>&1
echo "1创建mysql用户和组" && sleep 2
/usr/sbin/groupadd mysql
/usr/sbin/useradd -s /sbin/nologin -g mysql mysql
else
echo "2创建mysql用户和组" && sleep 2
/usr/sbin/groupadd mysql
/usr/sbin/useradd -s /sbin/nologin -g mysql mysql
fi
#配置文件限制
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
echo "fs.file-max=65535" >> /etc/sysctl.conf
#安装程序
#安装前准备
echo "unzip starting......"
tar -zxf $MYSQL_TAR -C $MYSQL_HOME
#创建软链接
cd $MYSQL_HOME
ln -s $MYSQL_UNZIP_FILE mysql
#创建目录
echo "创建mysql相关文件目录" && sleep 2
mkdir -p $MYSQL_DATA
chown -R mysql:mysql $MYSQL_DATA
chmod -R 770 $MYSQL_DATA
#配置用户环境变量
echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profile
#配置文件(先备份后创建)
if [ -s /etc/my.cnf ]; then
mv /etc/my.cnf /etc/my.cnf.$TIME.bak
fi
cat $MYSQL_FILE/mysql57.cnf > /etc/my.cnf
#初始化数据库
echo "initializing......"
mysqld --initialize --user=mysql
#mysql服务设置,启动mysql
cd $MYSQL_HOME/mysql
#将启动脚本加入到系统服务,并设置为开机启动启动
cp -rf $MYSQL_HOME/mysql/support-files/mysql.server /etc/init.d/mysql.server
chkconfig --add mysql.server
chkconfig mysql.server on
chkconfig --list
echo "mysql starting......"
service mysql.server start
#查看安装是否有报错
echo "=============================="
grep 'error' $MYSQL_DATA/error.log
#查看是否启动mysql
echo "=============================="
ps -ef|grep mysql
#查看root随机密码
echo "==============================password"
cd $MYSQL_DATA
a1=`grep 'A temporary password' error.log | awk -F"[email protected]: " '{ print $2}' `
#登录数据库
mysql -uroot -p${a1} --connect-expired-password <<EOF
set password = '[email protected]';
create user 'system'@'%' identified by '[email protected]018';
grant all privileges on *.* to 'system'@'%' with grant option;
exit
EOF
#重启mysql
sleep 1
service mysql.server restart
echo "==============================install success"
#END
2、配置文件内容
vi /home/meng/mysql57.cnf
[mysqld]
########basic settings########
server-id = 11 #如为主备库需要不相同
port = 3306
user = mysql
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
datadir = /data/mysql_data #数据文件目录
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
join_buffer_size = 134217728
tmp_table_size = 67108864
tmpdir = /tmp
max_allowed_packet = 16777216
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
interactive_timeout = 1800
wait_timeout = 1800
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
########log settings########
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 90
long_query_time = 2
min_examined_row_limit = 100
########replication settings########
master_info_repository = TABLE
relay_log_info_repository = TABLE
log-bin=master-bin
log-bin-index=master-bin.index
sync_binlog = 1
#gtid_mode = on
#enforce_gtid_consistency = 1
#log_slave_updates
binlog_format = row
relay_log = relay.log
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave_skip_errors = ddl_exist_errors
########innodb settings########
innodb_page_size = 16384 #页大小,咨询是否有特殊需求
innodb_buffer_pool_size = 1G #根据系统内存设置,一般为总内存的80%,可使用free -g查看内存大小
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 500
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
#innodb_log_group_home_dir = /redolog/
#innodb_undo_directory = /undolog/
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 1
innodb_log_file_size = 128M
innodb_log_buffer_size = 16777216
innodb_purge_threads = 1
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
########semi sync replication settings########
plugin_dir=/usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
#END
上一篇: PHP代码多种加密方式
下一篇: java基于des3的加密解密