MariaDB单机双实例配置说明
安装
- 推荐操作系统,CentOS7, yum install mariadb-server
配置
以下配置均是以CentOS7来进行
- 在/etc/my.cnf.d/建立两个文件3306.cnf,3307.cnf
[mysqld0]
basedir = /usr
character_set_server = utf8
collation_server = utf8_unicode_ci
datadir = /opt/data0
default_storage_engine = InnoDB
default_time_zone = '+8:00'
event_scheduler = 1
init_connect = 'set names utf8;'
lower_case_table_names = 1
memlock = 0
pid_file = /opt/data0/mysql.pid
port = 3306
skip_external_locking = 1
socket = /opt/data0/mysql.sock
tmpdir = /dev/shm
user = mysql
general_log = 0
general_log_file = /opt/data0/general_query.log
log_output = FILE
log_error = /opt/data0/mysqld.log
log_warnings = 2
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_verbosity = query_plan
long_query_time = 1
min_examined_row_limit = 100
slow_query_log = 1
slow_query_log_file = /opt/data0/slow_query.log
gtid_strict_mode = 1
transaction_isolation = READ-COMMITTED
innodb_data_home_dir = /opt/data0
innodb_log_group_home_dir = /opt/data0
innodb_undo_directory = /opt/data0
binlog_cache_size = 4M
binlog_checksum = crc32
binlog_format = row
expire_logs_days = 30
log_bin = /opt/data0/mysql-bin
max_binlog_cache_size = 128M
max_binlog_size = 1G
sync_binlog = 1
max_relay_log_size = 1G
relay_log = /opt/data0/relay-bin
relay_log_index = /opt/data0/relay-bin.index
relay_log_info_file = relay-log.info
relay_log_purge = 1
relay_log_recovery = 1
sync_relay_log = 10000
- 创建数据库文件,其中应区分06,07所在的文件夹
mysql_install_db --datadir=/opt/data0 --user=mysql --force --defaults-file=/etc/my.cnf.d/3306.cnf
mysql_install_db --datadir=/opt/data1 --user=mysql --force --defaults-file=/etc/my.cnf.d/3307.cnf
- 创建Systemd控制文件
mkdir /etc/systemd/system/[email protected]
#
# /etc/systemd/system/[email protected]
#
[Unit]
Description=Multi-Instance MariaDB Service
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
# true is needed for the ExecStartPre
PermissionsStartOnly=true
ExecStartPre=/usr/bin/mkdir -p /opt/data%i
ExecStartPre=/usr/bin/chown mysql:mysql /opt/data%i -R
ExecStart=/usr/bin/mysqld_multi start %i
ExecStop=/usr/bin/mysqld_multi stop %i
LimitNOFILE=102400
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=true
- 启动服务
systemctl start mariadb@{0,1}
- 配置服务器账户密码
mysqladmin -hlocalhost -P3306 --protocol=tcp password abc
mysqladmin -hlocalhost -P3307 --protocol=tcp password abc
- 本地登陆数据库,此时与正常操作数据库一致
mysql -P3306 --protocol=tcp -uroot -pabc
mysql -P3307 --protocol=tcp -uroot -pabc