龙空技术网

CentOS7.x shell脚本使用mysql_multi自动安装MySQL5.7.28多实例

运维Danrtsey 87

前言:

今天朋友们对“centosmysql脚本”大约比较珍视,兄弟们都想要知道一些“centosmysql脚本”的相关文章。那么小编在网络上收集了一些关于“centosmysql脚本””的相关文章,希望小伙伴们能喜欢,我们快快来学习一下吧!

在我的前一篇文章中描述了手动安装mysql多实例的过程,今天这一章节,我将它的手动安装过程,编写成脚本来自动安装:

以下是脚本中的几点说明:1、mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz包上传路径: /opt如果没有此软件包,请将此脚本中如下代码行去掉 # 号注释,自动联网下载(下载过程很慢,建议提前下载并上传到/opt路径下)

wget -c 

2、mysql数据库脚本上传路径: /opt 包含如下文件(需要修改sql文件中的实例名)

testone.sqltesttwo.sql

4、根据服务器磁盘分配情况,创建对应软链接,例如:

mkdir /home/dataln -s /home/data/ /data

5、修改(确保局域网内值唯一)

mysql3306.cnf 的 server_id = 3306mysql3307.cnf 的 server_id = 3307

6、注意修改预设的root密码与apps应用连接密码

Multi_PWD="Multi.db"dbone_appspwd="testone3306"dbtwo_appspwd="testtwo3307"

7、修改testone.sql数据库实例 testone 用户名 testone 及对应的密码 testone3306

create database testone default character set utf8 collate utf8_bin;grant select,insert,update,delete,create,execute on testone.* to 'testone'@'%' identified by 'testone3306';

8、修改testone.sql导入数据库时的数据库实例名 testone

$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbOneSockfile} --comments testone < testone.sql

9、修改testtwo.sql数据库实例 testtwo 用户名 testtwo 及对应的密码 testtwo3307

create database testtwo default character set utf8 collate utf8_bin;grant select,insert,update,delete,create,execute on testtwo.* to 'testtwo'@'%' identified by 'testtwo3307';

10、修改testtwo.sql导入数据库时的数据库实例名 testtwo

$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbTwoSockfile} --comments testtwo < testtwo.sql
 #!/bin/bash################################################################################################# Install software -- Install Mysql 5.7 on CentOS 7# Author:Danrtsey# mail:mydefiniteaim@126.com# History: 2020/01/15 Asa release################################################################################################[ -f /etc/init.d/functions ]&& . /etc/init.d/functions###Check if user is rootif [ $UID -ne 0 ]; then    echo "Error: This script must be executed as root."    exit 1fiecho "################################################################################################"echo "                      自动安装   MySQL 5.7      on Redhat/CentOS Linux                           "echo "################################################################################################"#set mysql root passwordecho "#########################       预设 Mysql root用户密码           ###############################"Multi_PWD="Multi.db"#set mysql apps passwordecho "#########################       预设 Mysql apps用户密码           ###############################"dbone_appspwd="testone3306"dbtwo_appspwd="testtwo3307"echo "################################       定义目录路径      #######################################"##define mysql directory configuration variableDbOneDatadir=/data/mysql/dbone3306/dataDbOneBinlogdir=/data/mysql/dbone3306/binlogDbOneLogdir=/data/mysql/dbone3306/logsDbOneSockfile=/data/mysql/dbone3306/mysql3306.sockDbOnepidfile=/data/mysql/dbone3306/mysqld3306.pidDbTwoDatadir=/data/mysql/dbtwo3307/dataDbTwoBinlogdir=/data/mysql/dbtwo3307/binlogDbTwoLogdir=/data/mysql/dbtwo3307/logsDbTwoSockfile=/data/mysql/dbtwo3307/mysql3307.sockDbTwopidfile=/data/mysql/dbtwo3307/mysqld3307.pidBaseDir=/usr/local/mysqlMYSQL_CMD_DIR=$BaseDir/binMycnf=/etc/my.cnfDbdir=/dataSoftwaredir=/optmkdir -pv /data/mysql/{dbone3306,dbtwo3307}mkdir -v /data/mysql/dbone3306/{logs,data,binlog}mkdir -v /data/mysql/dbtwo3307/{logs,data,binlog}echo "################################################################################################"echo "                                        修改系统参数                                             "echo "################################################################################################"###set the ip in hostshostsset() {echo "############################   Ip&Hosts Configuration  #######################################"hostname=`hostname`ip=`ip a|grep 'inet '|grep -v '127.0.0.1'|awk '{print $2}'|awk -F '/' '{print $1}'`for i in ${ip}do    a=`grep "${i}" /etc/hosts`    if [ ! -n "${a}" ];then        echo "${i} ${hostname}" >> /etc/hosts     else        break    fidone}ntp() {yum -y install ntp >/dev/null 2>&1systemctl enable ntpdecho 'server ntp1.aliyun.com' >> /etc/ntp.confecho 'server ntp2.aliyun.com' >> /etc/ntp.confsystemctl start ntpdif [ $? != 0 ]; then   errorExit 'ntp 启动未成功'   exit 2fi  return 0}syspro() {sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/configsetenforce 0ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeecho 'LANG="en_US.UTF-8"' >> /etc/profile && source /etc/profilecat >>/etc/security/limits.conf<<EOF* soft nproc 65535* hard nproc 65535* soft nofile 65535* hard nofile 65535EOFcat >> /etc/sysctl.conf<<EOFnet.core.somaxconn = 65535net.core.netdev_max_backlog = 65535net.ipv4.tcp_max_syn_backlog = 65535net.ipv4.tcp_fin_timeout = 10net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_keepalive_time = 120net.ipv4.tcp_keepalive_intvl = 30net.ipv4.tcp_keepalive_probes = 3vm.swappiness = 0net.ipv4.ip_forward=1net.bridge.bridge-nf-call-iptables=1net.ipv4.neigh.default.gc_thresh1=4096net.ipv4.neigh.default.gc_thresh2=6144net.ipv4.neigh.default.gc_thresh3=8192kernel.shmmax = 25769803774kernel.shmmni = 4096kernel.shmall = 16777216kernel.sem = 1010 129280 1010 128net.ipv4.ip_local_port_range = 9000 65500net.core.rmem_default = 4194304net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048576fs.aio-max-nr = 1048576fs.file-max = 6815744EOFmodprobe br_netfiltersysctl -p}fwport() {firewall-cmd --permanent --zone=public --add-port=3306/tcpfirewall-cmd --permanent --zone=public --add-port=3307/tcpfirewall-cmd --reload}clean() {echo "################################    删除旧Mysql、Maria    #######################################"    rpm -qa|grep mysql    rpm -qa|grep mariadb    yum -y remove mysql* >/dev/null 2>&1    yum -y remove mariadb* >/dev/null 2>&1if [ $? -eq 0 ];then   echo -e " \033[32m mariadb remove success!! \033[0m"else  echo -e "\e[31;47;5m mariadb remove failed!! \e[0m"  exit 3  fi#Backup old my.cnfif [ -s /etc/my.cnf ]; then    mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bakfi}# 添加用户和组addusers() {grep mysql /etc/passwdRETVAL=$?if [ $RETVAL -ne 0 ];then   groupadd mysql   useradd mysql -g mysql -s /sbin/nologin -M     action "mysql user added successfully" /bin/true  else      action " $(echo -e " mysql user already exists ")" /bin/true      exit 4ficat >> /etc/profile<<EOFif [ $USER = "mysql" ]; thenif [ $SHELL = "/bin/ksh" ]; thenulimit -p 16384ulimit -n 65536elseulimit -u 16384 -n 65536fifiEOFsource /etc/profile}#install mysql-5.7.28dbinstall() {echo "################################       开始下载安装      #######################################"yum -y install bzr zlib-devel gcc-c++ ncurses ncurses-devel libev make cmake gcc autoconf automake zlib libxml libgcrypt libtool bison perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL perl-Digest-MD5 rsync perl-Data-Dumper net-tools wget vim openssl openssl-devel >/dev/null 2>&1if [ $? -eq 0 ];then   echo -e " \033[32m yum install success!! \033[0m"else  echo -e "\e[31;47;5m yum install failed!! \e[0m"  exit 5  ficd $Softwaredir#wget -c  xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gzif [ $? -eq 0 ];then   echo -e " \033[32m tar.gz decompression success!! \033[0m"else  echo -e "\e[31;47;5m tar.gz decompression failed!! \e[0m"  exit 6  fimv mysql-5.7.28-linux-glibc2.12-x86_64 $BaseDirchown -R mysql:mysql $BaseDirchown -R mysql:mysql $Dbdir}#set my.cnf configfilesetmycnf() {echo "################################    配置  my.cnf      #######################################"cat >$Mycnf<<EOF[mysqld_multi]mysqld     = ${BaseDir}/bin/mysqldmysqladmin = ${BaseDir}/bin/mysqladminlog = /data/mysql/mysqld_multi.log #user=root#pass=[mysql]prompt="\u@jsshapp \R:\m:\s [\d]> "no-auto-rehash[mysqld3306]user                                = mysqlport                                = 3306symbolic-links                      = 0#basedir                             = /usr/datadir                             = ${DbOneDatadir}socket                              = ${DbOneSockfile}pid-file                            = ${DbOnepidfile}server_id                           = 3306character_set_server                = utf8max_connections                     = 1000skip_name_resolve                   = 1open_files_limit                    = 65536thread_cache_size                   = 64table_open_cache                    = 4096table_definition_cache              = 1024table_open_cache_instances          = 64max_prepared_stmt_count             = 1048576explicit_defaults_for_timestamp     = truelog_timestamps                      = systembinlog_format                       = rowlog_bin                           = ${DbOneBinlogdir}/mysql-binbinlog_rows_query_log_events        = onexpire_logs_days                    = 7binlog_cache_size                   = 4Mmax_binlog_cache_size               = 2Gmax_binlog_size                     = 1Gsync_binlog                         = 1log_bin_trust_function_creators     = 1slow_query_log                      = onslow_query_log_file                 = ${DbOneDatadir}/slow.loglog-error                           = ${DbOneLogdir}/error.loglog_queries_not_using_indexes      = onlong_query_time                     = 1.000000gtid_mode                           = onenforce_gtid_consistency            = ondefault_storage_engine              = innodbdefault_tmp_storage_engine          = innodbinnodb_data_file_path               = ibdata1:12M:autoextend:max:2000Minnodb_temp_data_file_path          = ibtmp1:12M:autoextend:max:2000Minnodb_buffer_pool_filename         = ib_buffer_poolinnodb_log_files_in_group           = 3innodb_log_file_size                = 512Minnodb_online_alter_log_max_size    = 1024Minnodb_open_files                   = 4096innodb_page_size                    = 16kinnodb_thread_concurrency           = 0innodb_read_io_threads              = 4innodb_write_io_threads             = 4innodb_purge_threads                = 4innodb_page_cleaners                = 4innodb_print_all_deadlocks          = oninnodb_lock_wait_timeout            = 20innodb_spin_wait_delay              = 128innodb_autoinc_lock_mode            = 2innodb_io_capacity                  = 200innodb_io_capacity_max              = 2000#innodb_flush_neighbors             = innodb_log_buffer_size              = 8Minnodb_flush_log_at_timeout         = 1innodb_flush_log_at_trx_commit      = 2innodb_buffer_pool_size             = 1024Minnodb_buffer_pool_instances        = 4autocommit                          = 1innodb_buffer_pool_dump_pct         = 25innodb_buffer_pool_dump_at_shutdown = ONinnodb_buffer_pool_load_at_startup  = ON[mysqld3307]user                                = mysqlport                                = 3307symbolic-links                      = 0lower_case_table_names              = 1#basedir                             = /usr/datadir                             = ${DbTwoDatadir}socket                              = ${DbTwoSockfile}pid-file                            = ${DbTwopidfile}server_id                           = 3307character_set_server                = utf8max_connections                     = 1000skip_name_resolve                   = 1open_files_limit                    = 65536thread_cache_size                   = 64table_open_cache                    = 4096table_definition_cache              = 1024table_open_cache_instances          = 64max_prepared_stmt_count             = 1048576explicit_defaults_for_timestamp     = truelog_timestamps                      = systembinlog_format                       = rowlog_bin                            = ${DbTwoBinlogdir}/mysql-binbinlog_rows_query_log_events        = onexpire_logs_days                    = 7binlog_cache_size                   = 4Mmax_binlog_cache_size               = 2Gmax_binlog_size                     = 1Gsync_binlog                         = 1slow_query_log                      = onslow_query_log_file                 = ${DbTwoDatadir}/slow.loglog-error                           = ${DbTwoLogdir}/error.loglog_queries_not_using_indexes      = onlong_query_time                     = 1.000000gtid_mode                           = onenforce_gtid_consistency            = ondefault_storage_engine              = innodbdefault_tmp_storage_engine          = innodbinnodb_data_file_path               = ibdata1:12M:autoextend:max:2000Minnodb_temp_data_file_path          = ibtmp1:12M:autoextend:max:2000Minnodb_buffer_pool_filename         = ib_buffer_poolinnodb_log_files_in_group           = 3innodb_log_file_size                = 512Minnodb_online_alter_log_max_size    = 1024Minnodb_open_files                   = 4096innodb_page_size                    = 16kinnodb_thread_concurrency           = 0innodb_read_io_threads              = 4innodb_write_io_threads             = 4innodb_purge_threads                = 4innodb_page_cleaners                = 4innodb_print_all_deadlocks          = oninnodb_lock_wait_timeout            = 20innodb_spin_wait_delay              = 128innodb_autoinc_lock_mode            = 2innodb_io_capacity                  = 200innodb_io_capacity_max              = 2000#innodb_flush_neighbors             = innodb_log_buffer_size              = 8Minnodb_flush_log_at_timeout         = 1innodb_flush_log_at_trx_commit      = 2innodb_buffer_pool_size             = 1024Minnodb_buffer_pool_instances        = 4autocommit                          = 1innodb_buffer_pool_dump_pct         = 25innodb_buffer_pool_dump_at_shutdown = ONinnodb_buffer_pool_load_at_startup  = ON[mysqldump]quickmax_allowed_packet = 32MEOF}#dbone initializedboneinitialize() {echo "################################      dbone 初始化     #######################################"$MYSQL_CMD_DIR/mysqld --defaults-file=$Mycnf --initialize --basedir=$BaseDir --user=mysql --datadir=$DbOneDatadir > $DbOneLogdir/error.log 2>&1if [ $? -eq 0 ];then   echo -e " \033[32m dbone initialize success!! \033[0m"else  echo -e "\e[31;47;5m dbone initialize failed!! \e[0m"  exit 7  filess $DbOneLogdir/error.log|grep 'A temporary password is generated for root@localhost:'A=$?count=0while [ $count -lt 10 ]do    if [ $A -eq 0 ];then        echo -e " \033[32m mysql initialize success!! \033[0m"        break    else        echo -e "\e[31;47;5m the result is null,check again!! \e[0m"        count=$[${count}+1]    fidone#create ssl_rsaecho "################################      dbone 生成ssl授权     #######################################"$MYSQL_CMD_DIR/mysql_ssl_rsa_setup --user=mysql --basedir=$BaseDir --datadir=$DbOneDatadirif [ $? -eq 0 ];then   echo -e " \033[32m create ssl_rsa success!! \033[0m"else  echo -e "\e[31;47;5m create ssl_rsa failed!! \e[0m"  exit 8fi}#dbtwo initializedbtwoinitialize() {echo "################################      dbtwo 初始化     #######################################"$MYSQL_CMD_DIR/mysqld --defaults-file=$Mycnf --initialize --basedir=$BaseDir --user=mysql --datadir=$DbTwoDatadir > $DbTwoLogdir/error.log 2>&1if [ $? -eq 0 ];then   echo -e " \033[32m dbtwo initialize success!! \033[0m"else  echo -e "\e[31;47;5m dbtwo initialize failed!! \e[0m"  exit 9filess $DbTwoLogdir/error.log|grep 'A temporary password is generated for root@localhost:'B=$?count=0while [ $count -lt 10 ]do    if [ $B -eq 0 ];then        echo -e " \033[32m mysql initialize success!! \033[0m"        break    else        echo -e "\e[31;47;5m the result is null,check again!! \e[0m"        count=$[${count}+1]    fidone#create ssl_rsaecho "################################      dbtwo 生成ssl授权     #######################################"$MYSQL_CMD_DIR/mysql_ssl_rsa_setup --user=mysql --basedir=$BaseDir --datadir=$DbTwoDatadirif [ $? -eq 0 ];then   echo -e " \033[32m create ssl_rsa success!! \033[0m"else  echo -e "\e[31;47;5m create ssl_rsa failed!! \e[0m"  exit 10fi}# start dbone service && change tmptroot pwddbonestart() {echo "################################      dbone 服务启动     #######################################"cat << EOF >> /etc/profileexport PATH=\$PATH:${BaseDir}/binEOFsource /etc/profilechown -R mysql:mysql $DbOneLogdir$MYSQL_CMD_DIR/mysqld_multi start 3306if [ $? -eq 0 ];thencount=0while [ $count -lt 120 ]docat $DbOneLogdir/error.log |grep '/data/mysql/dbone3306/mysql3306.sock'C=$?    if [ $C -eq 0 ];then        echo -e " \033[32m dbone start success!! \033[0m"        break    else        count=$[${count}+1]        echo -e "\e[31;47;5m 3306 is not exist check the $count time!! \e[0m"        sleep 1    fidoneelse  echo -e "\e[31;47;5m dbone use mysqld_multi start failed,please check the error.log !! \e[0m"  cat $DbOneLogdir/error.log |grep ERROR  exit 11fiecho "################################   获取 dbone root用户临时密码     #######################################"DbOnedbTempPass=$(less $DbOneLogdir/error.log|grep 'A temporary password is generated for root@localhost:' |awk  '{print $NF}')echo $DbOnedbTempPassecho "################################     自动修改 dbone root用户初始密码       ###############################"$MYSQL_CMD_DIR/mysqladmin -uroot -p"$DbOnedbTempPass" -S $DbOneSockfile password $Multi_PWDif [ $? -eq 0 ];then   echo -e " \033[32m dbone rootpwd changed success!! \033[0m"else  echo -e "\e[31;47;5m dbone rootpwd changed failed!! \e[0m"  exit 12fiecho "################################     验证 dbone root用户初始密码       ###############################"MYSQL_CMD="$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbOneSockfile}"$MYSQL_CMD -e "show databases;" | grep information_schemaif [ $? -eq 0 ];then   echo -e " \033[32m dbone rootpwd is correct!! \033[0m"else  echo -e "\e[31;47;5m dbone rootpwd is  wrong!! \e[0m"  exit 13fiecho "################################  修改 my.cnf multi 启动用户与密码  #######################################"sed -i "s@^#user=root@user=root@g" /etc/my.cnfsed -i "s@^#pass=@pass=${Multi_PWD}@g" /etc/my.cnfif [ $? -eq 0 ];then   echo -e " \033[32m my.cnf changed success!! \033[0m"else  echo -e "\e[31;47;5m my.cnf changed failed!! \e[0m"  exit 14fiecho "################################   验证 dbone 服务关闭是否正常     #######################################"$MYSQL_CMD_DIR/mysqld_multi stop 3306netstat -tnlp|grep 3306if [ $? -ne 0 ];then   echo -e " \033[32m dbone stop success!! \033[0m"else  echo -e "\e[31;47;5m dbone stop failed!! \e[0m"  exit 15fi}# start dbtwo service && change tmptroot pwddbtwostart() {echo "################################      dbtwo 服务启动     #######################################"source /etc/profilechown -R mysql:mysql $DbTwoLogdir$MYSQL_CMD_DIR/mysqld_multi start 3307if [ $? -eq 0 ];thencount=0while [ $count -lt 120 ]docat $DbTwoLogdir/error.log |grep '/data/mysql/dbtwo3307/mysql3307.sock'D=$?    if [ $D -eq 0 ];then        echo -e " \033[32m dbtwo start success!! \033[0m"        break    else        count=$[${count}+1]        echo -e "\e[31;47;5m 3307 is not exist check the $count time!! \e[0m"        sleep 1    fidoneelse  echo -e "\e[31;47;5m dbtwo use mysqld_multi start failed,please check the error.log  !! \e[0m"  cat $DbTwoLogdir/error.log |grep ERROR  exit 16fiecho "################################  获取 dbtwo root用户临时密码     #######################################"DbTwodbTempPass=$(less $DbTwoLogdir/error.log|grep 'A temporary password is generated for root@localhost:' |awk  '{print $NF}')echo $DbTwodbTempPassecho "################################     自动修改 dbtwo root用户初始密码       ###############################"$MYSQL_CMD_DIR/mysqladmin -uroot -p"$DbTwodbTempPass" -S $DbTwoSockfile password $Multi_PWDif [ $? -eq 0 ];then   echo -e " \033[32m dbtwo rootpwd changed success!! \033[0m"else  echo -e "\e[31;47;5m dbtwo rootpwd changed failed!! \e[0m"  exit 17fiecho "################################     验证 dbtwo root用户初始密码       ###############################"MYSQL_CMD="$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbTwoSockfile}"$MYSQL_CMD -e "show databases;" | grep information_schemaif [ $? -eq 0 ];then   echo -e " \033[32m dbtwo rootpwd is correct!! \033[0m"else  echo -e "\e[31;47;5m dbtwo rootpwd is  wrong!! \e[0m"  exit 18fiecho "################################   验证 dbtwo 服务关闭是否正常     #######################################"$MYSQL_CMD_DIR/mysqld_multi stop 3307netstat -tnlp|grep 3307if [ $? -ne 0 ];then   echo -e " \033[32m dbtwo stop success!! \033[0m"else  echo -e "\e[31;47;5m dbtwo stop failed!! \e[0m"  exit 19fi}dboneimp() {echo "###############################  再次重启 dbone 数据库确认系统服务正常  ##################################"source /etc/profilecat >$DbOneLogdir/error.log<<EOFuse the mysqld_multi to  start the dbone againEOFchown -R mysql:mysql $DbOneLogdir$MYSQL_CMD_DIR/mysqld_multi start 3306if [ $? -eq 0 ];thencount=0while [ $count -lt 120 ]docat $DbOneLogdir/error.log |grep '/data/mysql/dbone3306/mysql3306.sock'E=$?    if [ $E -eq 0 ];then        echo -e " \033[32m dbone start success!! \033[0m"        break    else        count=$[${count}+1]        echo -e "\e[31;47;5m 3306 is not exist check the $count time!! \e[0m"        sleep 1    fidoneelse  echo -e "\e[31;47;5m dbone use mysqld_multi start failed,please check the error.log !! \e[0m"  cat $DbOneLogdir/error.log |grep ERROR  exit 20fiecho "###############################        创建 testone 库           ##################################"MYSQL_CMD="$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbOneSockfile}"$MYSQL_CMD -e "create database testone default character set utf8 collate utf8_bin;grant select,insert,update,delete,create,alter,execute on testone.* to 'testone'@'%' identified by 'testone3306';flush privileges;" > /tmp/dbone_create.logcat /tmp/dbone_create.log |grep "Table 'mysql.servers' doesn't exist"if [ $? -eq 0 ] then   echo -e "\e[31;47;5m 创建 testone 数据库失败!\e[0m"   exit 21fi$MYSQL_CMD -e "show databases;" | grep testoneif [ $? -eq 0 ] then   echo -e " \033[32m 创建 testone 数据库成功!! \033[0m"else   echo -e "\e[31;47;5m 创建 testone 数据库失败!\e[0m"   exit 22fiecho "###############################           testone 导入数据            ##################################"cd $Softwaredir$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbOneSockfile} testone < testone.sqlif [ $? -eq 0 ] then   echo -e " \033[32m 导入数据成功!! \033[0m"else   echo -e "\e[31;47;5m 导入数据失败!\e[0m"   exit 23fi}dbtwoimp() {echo "###############################   再次重启 dbtwo 数据库确认系统服务正常   ##################################"source /etc/profilecat >$DbTwoLogdir/error.log<<EOFuse the mysqld_multi to  start the dbtwo againEOFchown -R mysql:mysql $DbTwoLogdir$MYSQL_CMD_DIR/mysqld_multi start 3307if [ $? -eq 0 ];thencount=0while [ $count -lt 120 ]docat $DbTwoLogdir/error.log |grep '/data/mysql/dbtwo3307/mysql3307.sock'F=$?    if [ $F -eq 0 ];then        echo -e " \033[32m dbtwo start success!! \033[0m"        break    else        count=$[${count}+1]        echo -e "\e[31;47;5m 3307 is not exist check the $count time!! \e[0m"        sleep 1    fidoneelse  echo -e "\e[31;47;5m dbtwo use mysqld_multi start failed,please check the error.log  !! \e[0m"  cat $DbTwoLogdir/error.log |grep ERROR  exit 24fiecho "###############################        创建 testtwo 库           ##################################"MYSQL_CMD="$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbTwoSockfile}"$MYSQL_CMD -e "create database testtwo default character set utf8 collate utf8_bin;grant select,insert,update,delete,create,alter,execute on testtwo.* to 'testtwo'@'%' identified by 'testtwo3307';flush privileges;" > /tmp/dbtwo_create.logcat /tmp/dbtwo_create.log |grep "Table 'mysql.servers' doesn't exist"if [ $? -eq 0 ] then   echo -e "\e[31;47;5m 创建 testtwo 数据库失败!\e[0m"   exit 25fi$MYSQL_CMD -e "show databases;" | grep testtwoif [ $? -eq 0 ] then   echo -e " \033[32m 创建 testtwo 数据库成功!! \033[0m"else   echo -e "\e[31;47;5m 创建 testtwo 数据库失败!\e[0m"   exit 26fiecho "###############################           testtwo 导入数据            ##################################"cd $Softwaredir$MYSQL_CMD_DIR/mysql -uroot -p"${Multi_PWD}" -S ${DbTwoSockfile} testtwo < testtwo.sqlif [ $? -eq 0 ] then   echo -e " \033[32m 导入数据成功!! \033[0m"else   echo -e "\e[31;47;5m 导入数据失败!\e[0m"   exit 27fi}main() {hostssetntpsysprofwportcleanaddusersdbinstallsetmycnfdboneinitializedbtwoinitializedbonestartdbtwostartdboneimpdbtwoimp}mainecho "#######################        安装完成 (请记录dbone数据库testone信息)          ##############################"echo "root密码:"echo -e "\e[31;47;5m $Multi_PWD \e[0m"echo "数据库实例连接密码:"echo -e "\e[30;47;5m $dbone_appspwd \e[0m"echo "#######################        安装完成 (请记录dbtwo数据库testtwo信息)          ##############################"echo "root密码:"echo -e "\e[31;47;5m $Multi_PWD \e[0m"echo "数据库实例连接密码:"echo -e "\e[30;47;5m $dbtwo_appspwd \e[0m"source /etc/profile

标签: #centosmysql脚本 #centosxshell连不上