mysql 5.7 添加多实例脚本

举报
snowofsummer 发表于 2021/04/28 12:08:18 2021/04/28
【摘要】 使用示例:[root@VM-16-10-centos script]# ./a.sh 1234mysql db port number is :123401:init os.02:init my.cnf.03:init db.2021-04-28T04:07:29.567003Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is dep...

使用示例:

[root@VM-16-10-centos script]# ./a.sh 1234
mysql db port number is :1234
01:init os.
02:init my.cnf.
03:init db.
2021-04-28T04:07:29.567003Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-28T04:07:29.567203Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2021-04-28T04:07:30.581445Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-04-28T04:07:30.774119Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-04-28T04:07:30.863338Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 409ae8a3-a7d7-11eb-a6a4-52540004487e.
2021-04-28T04:07:30.874897Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-04-28T04:07:30.875810Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
04:startup db.
05:chk db info.
startup script is /mysqldata/1234/mysql.1234
Starting MySQL. SUCCESS! 
root      1316     1  2 12:07 pts/3    00:00:00 /bin/sh /mysql/mysql/bin/mysqld_safe --datadir=/mysqldata/1234/data --pid-file=/mysqldata/1234/run/db.pid
mysql     1493  1316  0 12:07 pts/3    00:00:00 /mysql/mysql/bin/mysqld --basedir=/mysql/mysql --datadir=/mysqldata/1234/data --plugin-dir=/mysql/mysql/lib/plugin --user=mysql --log-error=/mysqldata/1234/log/db.log --pid-file=/mysqldata/1234/run/db.pid --socket=/mysqldata/1234/mysql.sock --port=1234

脚本:

#!/bin/bash
#test mysql version mysql-5.7.18-linux-glibc2.5-x86_64.
basedir=/mysql/mysql
datadir=/mysqldata
dbfile=$datadir/$1
port=$1

if [ $# -ne 1 ]
then
echo "Usage: `basename $0` {PORT-NUMBER}"
else 
echo  "mysql db port number is :$1"
fi

initos() {
mkdir $dbfile
mkdir $dbfile/data
mkdir $dbfile/log
mkdir $dbfile/run
touch $dbfile/log/db.log
chown -R mysql:mysql $datadir/$1
}

initcnf() {
cat > $dbfile/my.cnf<<EOF
[mysqld]
port=$port
datadir=$dbfile/data
socket=$dbfile/mysql.sock
pid-file=$dbfile/run/db.pid
[mysqld_safe]
log-error=$dbfile/log/db.log
pid-file=$dbfile/run/db.pid
EOF
}

initdb() {
$basedir/bin/mysqld --defaults-file=$dbfile/my.cnf  --user=mysql --initialize-insecure
}

startup() {
#add startup script
mv $dbfile/my.cnf $dbfile/data/
cp $basedir/support-files/mysql.server $dbfile/mysql.$port
sed -i 46{s#basedir=#basedir=$basedir#} $dbfile/mysql.$port
sed -i 47{s#datadir=#datadir=$dbfile/data#} $dbfile/mysql.$port
sed -i "48i ln -s $dbfile/data/my.cnf /etc/my.cnf"  $dbfile/mysql.$port
sed -i '48i rm -rf /etc/my.cnf' $dbfile/mysql.$port
}

chk() {
#startup
echo "startup script is $dbfile/mysql.$port"
$dbfile/mysql.$port start
ps -ef|grep mysql|grep -v grep
}

echo 01:init os.
initos
echo 02:init my.cnf.
initcnf
echo 03:init db.
initdb
echo 04:startup db.
startup
echo 05:chk db info.
chk
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。