一键部署MySQL5.7多端口脚本

774次阅读
没有评论

共计 17647 个字符,预计需要花费 45 分钟才能阅读完成。

为了部署与测试方便,整理了一份部署 MySQL5.7 多端口的脚本,妥妥的爽
以下脚本是部署的 9 个数据库,要增减请自行修改
要求不高,你至少得认真给个评论嘛...

#!/bin/bash
#chmod u+x mysqld_multi.sh
#脚本执行方式
#source ./mysqld_multi.sh
#yum install wget -y
yum install wget mysql-devel perl perl-devel libncurses* -y
cd /opt
#wget https://cdn.mysql.com//archives/mysql-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
#baseMysqlDir=/usr/local/tarsPkg/mysql-5.7.22-linux-glibc2.12-x86_64

[hidecontent type="payshow" desc="隐藏内容:付费阅读"]

## 创建 MySQL 软链接
#ln -s ${baseMysqlDir} /usr/local/mysql

## 创建 MySQL 用户
useradd -r -s /sbin/nologin mysql

## 在 MySQL 二进制包目录中创建 mysql-files 目录
mkdir -v /usr/local/mysql/mysql-files

## 创建多实例数据目录
mkdir -vp /data/mysql_data{1..9} 

## 修改 MySQL 二进制包目录的所属用户与所属组
#chown root.mysql -R ${baseMysqlDir}
chown root.mysql -R /usr/local/mysql

## 修改 MySQL 多实例数据目录与 数据导入 / 导出专放目录的所属用户与所属组
chown mysql.mysql -R /usr/local/mysql/mysql-files /data/mysql_data{1..9}

## 初始化各个实例 [初始化完成后会自带随机密码在输出日志中]
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data5
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data6
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data7
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data8
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data9

## 各实例开启 SSL 连接
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data5
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data6
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data7
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data8
/usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data9

#创建 my.cnf
cat > /etc/my.cnf<<EOF
[mysqld_multi]
mysqld    = /usr/local/mysql/bin/mysqld 
mysqladmin = /usr/local/mysql/bin/mysqladmin
log        = /tmp/mysql_multi.log

[mysqld1]
datadir = /data/mysql_data1
socket = /tmp/mysql.sock1
tmpdir=/data/mysql_data1
port = 3306
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld2]
datadir = /data/mysql_data2
socket = /tmp/mysql.sock2
tmpdir=/data/mysql_data2
port = 3307
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld3]
datadir = /data/mysql_data3
socket = /tmp/mysql.sock3
tmpdir=/data/mysql_data3
port = 3308
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld4]
datadir = /data/mysql_data4
socket = /tmp/mysql.sock4
tmpdir=/data/mysql_data4
port = 3309
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld5]
datadir = /data/mysql_data5
socket = /tmp/mysql.sock5
tmpdir=/data/mysql_data5
port = 3310
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld6]
datadir = /data/mysql_data6
socket = /tmp/mysql.sock6
tmpdir=/data/mysql_data6
port = 3311
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld7]
datadir = /data/mysql_data7
socket = /tmp/mysql.sock7
tmpdir=/data/mysql_data7
port = 3312
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld8]
datadir = /data/mysql_data8
socket = /tmp/mysql.sock8
tmpdir=/data/mysql_data8
port = 3313
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld9]
datadir = /data/mysql_data9
socket = /tmp/mysql.sock9
tmpdir=/data/mysql_data9
port = 3314
user = mysql
innodb_file_per_table=1
#innodb_open_files=2048
innodb_file_format=Barracuda
#innodb_file_format_check = ON
#innodb_log_file_size = 512M
innodb_strict_mode = 0  #修复导入数据报错 1118 问题
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
#sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
#slow-query-log-file=/data/mysql/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


#innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4
lower_case_table_names = 1
#skip-grant-tables

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
EOF

## 复制多实例脚本到服务管理目录下 [/etc/init.d/]
cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi

## 添加脚本执行权限
chmod +x /etc/init.d/mysqld_multi

## 添加 mysql 到 path
echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profile

## 添加进 service 服务管理
#chkconfig --add mysqld_multi #感觉没有生效
#chkconfig mysqld_multi on    #感觉没有生效

#创建 MySql 开机启动 bash 文件
cat > /etc/rc.d/mysqld_multi_start.sh<<EOF
#!/bin/bash
export PATH=/usr/local/mysql/bin:$PATH
/etc/init.d/mysqld_multi start
EOF
chmod +x /etc/rc.d/mysqld_multi_start.sh

#添加到开机启动文件 /etc/rc.d/rc.local
sed -i '$a\/etc/rc.d/mysqld_multi_start.sh' /etc/rc.d/rc.local

#开机启动文件如果没有执行权限,也需要授权一下(非常重要)
chmod +x /etc/rc.d/rc.local

## 添加进 service 服务管理
export PATH=/usr/local/mysql/bin:$PATH

## 启动 mysqld_multi 服务
/etc/rc.d/mysqld_multi_start.sh

## 查个多实例状态
sleep 20
/etc/init.d/mysqld_multi report
#ps -ef | grep mysqld #查看进程

#以下为修改密码
#pwd='scit028@123'
#mysql -uroot -S/tmp/mysql.sock1<< EOF
#set password = '${pwd}';
#flush privileges;
#EOF

[/hidecontent]

打赏小哥

一键部署 MySQL5.7 多端口脚本微信打赏 一键部署 MySQL5.7 多端口脚本支付宝打赏

正文完
 0
评论(没有评论)