mysql-5.7.21 配置多实例 — 独立配置文件方式

xiaohai 2020-10-23 12:48:52 353人围观 标签: Mysql 
简介通过使用多个配置文件来启动不同的进程,以此来实现多实例。本文主要是记录mysql-5.7.21 配置多实例配置过程。

参照mysql-5.7.21安装到配置文件处理之前

1、创建目录
mkdir -p /apps/mysql_data/{3306,3307}
2、分别在3306、3307下建立配置文件my.cnf(下面只展示一个,替换端口即可)
[client]
port = 3307
socket = /apps/mysql_data/3307/mysql.sock
[mysqld]
server_id=1
port = 3307
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket =  /apps/mysql_data/3307/mysql.sock
basedir = /apps/mysql
datadir = /apps/mysql_data/3307/data
pid-file = /apps/mysql_data/3307/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
explicit_defaults_for_timestamp=true
#####[innodb]
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend
innodb_undo_tablespaces=3
#####[log]
log_error = /apps/mysql_data/3307/log/mysql-error.log 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
3、初始化数据库(这里我们采用不要初始密码的情况)
./bin/mysqld --defaults-file=/apps/mysql_data/3306/my.cnf --initialize-insecure --datadir=/apps/mysql_data/3306/data/ --basedir=/apps/mysql  --user=mysql
./bin/mysqld --defaults-file=/apps/mysql_data/3307/my.cnf --initialize-insecure --datadir=/apps/mysql_data/3307/data/ --basedir=/apps/mysql  --user=mysql
4、运行实例
./bin/mysqld_safe --defaults-file=/apps/mysql_data/3306/my.cnf --datadir=/apps/mysql_data/3306/data/ --basedir=/apps/mysql  --user=mysql &
./bin/mysqld_safe --defaults-file=/apps/mysql_data/3307/my.cnf --datadir=/apps/mysql_data/3307/data/ --basedir=/apps/mysql  --user=mysql &
5、设置密码
./bin/mysqladmin -uroot -p password 123456 -S /apps/mysql_data/3306/mysql.sock
./bin/mysqladmin -uroot -p password 123456 -S /apps/mysql_data/3307/mysql.sock
6、本地登录
./bin/mysql -uroot -p -S /apps/mysql_data/3306/mysql.sock
./bin/mysql -uroot -p -S /apps/mysql_data/3307/mysql.sock
7、关闭某个实例
./bin/mysqladmin -uroot -p -S /apps/mysql_data/3306/mysql.sock shutdown
./bin/mysqladmin -uroot -p -S /apps/mysql_data/3307/mysql.sock shutdown

Mysql通过system命令调用系统shell命令

1、报错:在执行登录操作的时候出现:
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

错误
解决方法:https://yq.aliyun.com/ziliao/42090 (未验证)