主从数据库挂载操作

文章目录

  • 安装mariadb
  • 修改配置文件
  • 重启数据库
  • 记得关闭防火墙
  • 在数据库可视化工具中操作
  • 数据库双主操作(高可用)

安装mariadb

安装

修改配置文件

vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
server-id=1
log-bin=mysql-bin

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

重启数据库

systemctl restart mariadb

记得关闭防火墙

systemctl stop firewalld

在数据库可视化工具中操作

/*从库*/
show master status;

记住master_log_file和master_log_pos

/*从库操作挂载*/
change master to master_host="主库IP",
master_port=3306,
master_user="用户名",
master_password="用户密码",
master_log_file="mysql-bin.000001",
master_log_pos=245;
/*启动*/
start slave;
/*检查*/
show slave status;
/*停止*/
stop slave;

数据库双主操作(高可用)

再主库挂载从即可双主:

/*从库*/
show master status;

记住master_log_file和master_log_pos

/*主库操作挂载*/
change master to master_host="从库IP",
master_port=3306,
master_user="用户名",
master_password="用户密码",
master_log_file="mysql-bin.000001",
master_log_pos=245;
/*启动*/
start slave;
/*检查*/
show slave status;
/*停止*/
stop slave;

本文地址:https://blog.csdn.net/super_yun/article/details/108573684

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐