Mysql(Mariadb)数据库主从
一、准备工作:
yum install mariadb-server.x86_64 mariadb.x86_64 -y
systemctl start mariadb.service && systemctl enable mariadb.service
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
二、主数据库master修改:
find / -name my.cnf
[mysqld]
log-bin=mysql-bin #开启二进制日志
server-id=1 #设置server-id
log-bin="/var/lib/mysql/" #设定生成的log文件名;
systemctl restart mariadb.service
mysql -hlocalhost -uroot -ppassword
MariaDB [(none)]> CREATE USER 'wxp'@'192.168.1.200' IDENTIFIED BY 'password';#创建用户
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'wxp'@'192.168.1.100';#分配权限
MariaDB [(none)]>flush privileges; #刷新权限
MariaDB [(none)]> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 492 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
三、从服务器slave修改:
find / -name my.cnf
[mysqld]server-id=2 #设置server-id,必须唯一
log-bin="/var/lib/mysql/" #设定生成的log文件名;
systemctl restart mariadb.service
mysql -hlocalhost -uroot -ppassword
MariaDB [(none)]> CHANGE MASTER TO
-> MASTER_HOST='192.168.3.91',
-> MASTER_USER='wxp',
-> MASTER_PASSWORD='password',
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=492;
mysql> select * from mysql.slave_master_info \G
MariaDB [(none)]>start slave;
MariaDB [(none)]> show slave status\G;
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.91
Master_User: wxp
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 492
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 492
Relay_Log_Space: 825
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
ERROR: No query specified
Until_Log_File:
MariaDB [(none)]> use test;
Database changed
MariaDB [test]> create table t1(Name varchar(18));
Query OK, 0 rows affected (0.03 sec)
MariaDB [test]> insert into t1(Name) values('wxp');
Query OK, 1 row affected (0.01 sec)
MariaDB [test]> select * from t1;
+------+
| Name |
+------+
| wxp |
+------+
1 row in set (0.00 sec)
[root@backup-3-218 ~]# mysql -hlocalhost -uroot -ppassword
MariaDB [(none)]> use test;
MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1 |
+----------------+
1 row in set (0.00 sec)
MariaDB [test]> select * from t1;
+------+
| Name |
+------+
| wxp |
+------+
1 row in set (0.00 sec)
# 不同步哪些数据库
# vim /etc/my.cnf
binlog-ignore-db = mysql
binlog-ignore-db = test
binlog-ignore-db = information_schema
# systemctl restart mariadb.service
# 只同步哪些数据库,除此之外,其他不同步 binlog-do-db = wxp
# 日志保留时间
expire_logs_days = 10
# 控制binlog的写入频率。每执行多少次事务写入一次
# 这个参数性能消耗很大,但可减小MySQL崩溃造成的损失
sync_binlog = 5
# 日志格式,建议mixed
# statement 保存SQL语句
# row 保存影响记录数据
# mixed 前面两种的结合
binlog_format = mixed
# 停止主从同步
mysql> stop slave;
# 连接断开时,重新连接超时时间
mysql> change master to master_connect_retry=50;
# 开启主从同步
mysql> start slave;
Mysql(Mariadb)数据库主从的更多相关文章
- MySQL/MariaDB数据库的主从级联复制
MySQL/MariaDB数据库的主从级联复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主从复制类型概述 1>.主从复制 博主推荐阅读: https://ww ...
- MySQL/MariaDB数据库的Galera高可用性集群实战
MySQL/MariaDB数据库的Galera高可用性集群实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Galera Cluster概述 1>.什么是Gale ...
- MySQL/MariaDB数据库的复制监控和维护
MySQL/MariaDB数据库的复制监控和维护 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.清理日志 1>.删除指定日志文件名称之前的日志(也可用基于时间) M ...
- MySQL/MariaDB数据库的主主复制
MySQL/MariaDB数据库的主主复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主主复制概述 1>.什么是主主复制 所谓的主主复制,说白了就是两台节点互为 ...
- MySQL/MariaDB数据库的主从复制
MySQL/MariaDB数据库的主从复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL复制概述 1>.传统扩展方式 垂直扩展(也叫向上扩展,Sacle ...
- MySQL/MariaDB数据库的性能测试
MySQL/MariaDB数据库的性能测试 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.数据库服务衡量指标 qps: query per second(每秒支持多少查询 ...
- MySQL/MariaDB数据库的MHA实现高可用实战
MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...
- MySQL/MariaDB数据库的PROXY实现读写分离
MySQL/MariaDB数据库的PROXY实现读写分离 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ProxySQL概述 1>.各家互联网公司读写分离的解决方案 m ...
- MySQL/MariaDB数据库的复制加密
MySQL/MariaDB数据库的复制加密 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL的安全问题 1>.基于SSL复制 在默认的主从复制过程或远程连接 ...
- MySQL/MariaDB数据库的复制过滤器
MySQL/MariaDB数据库的复制过滤器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.复制过滤器概述 1>.复制器过滤器功能 让从节点仅复制指定的数据库,或指 ...
随机推荐
- Spring+Struts2+Hibernate框架搭建
SSH框架版本:Struts-2.3.30 + Spring-4.2.2 + Hibernate5.2.2 下图是所需要的Jar包: 下面是项目的结构图: 1.web.xml <?xml ...
- 浅谈JQuery
一.什么是JQuery? JQuery是第三方开发的执行DOM操作的极简化的函数库. 执行DOM操作:JQuery还是在执行DOM操作 1.学习JQuery还是在学习DOM 2.五件事:增删改查 事件 ...
- Redis学习笔记(十二) 复制(上)
偷个懒,晚上工作忙的太晚,整个复制功能的内容还没有写完,这里先说一下复制功能的简单应用. 在Redis中,用户可以通过执行SLAVEOF命令或者设置slaveof选项,让一个服务器去复制另一个服务器, ...
- k8s搭建实操记录一(master)
#1)关闭CentOS7自带的防火墙服务 systemctl disable firewalld systemctl stop firewalld swapoff -a ##虚拟机要关闭交换 ...
- ShoneSharp语言(S#)的设计和使用介绍系列(11)—“类”披炫服靓妆化成“表”
ShoneSharp语言(S#)的设计和使用介绍 系列(11)—“类”披炫服靓妆化成“表” 作者:Shone 声明:原创文章欢迎转载,但请注明出处,https://www.cnblogs.com/Sh ...
- 关于 conda中的 lxml 无法导入 etree 问题
找到你conda的安装目录下\Lib\site-packages下的两个文件夹lxml和lxml-4.3.4.dist-info,将这两个文件夹删除. 执行命令pip install lxml 重新安 ...
- 面试中很值得聊的二叉树遍历方法——Morris遍历
Morri遍历 通过利用空闲指针的方式,来节省空间.时间复杂度O(N),额外空间复杂度O(1).普通的非递归和递归方法的额外空间和树的高度有关,递归的过程涉及到系统压栈,非递归需要自己申请栈空间,都具 ...
- 如何利用CSS选择器抓取京东网商品信息
前几天小编分别利用Python正则表达式.BeautifulSoup.Xpath分别爬取了京东网商品信息,今天小编利用CSS选择器来为大家展示一下如何实现京东商品信息的精准匹配~~ CSS选择器 目前 ...
- [Objective-C] 013_文件系统(File System)
在前面三篇关于数据持久化,我们都用涉及到文件(plist文件,数据库文件),它们都是把它们存储在document目录下.iOS的文件机制是沙盒机制,应用只能访问自己应用目录下的文件.iOS应用产生的内 ...
- require.js与IDEA的配合
本文主要讲述在html中使用requirejs时,如何让IDEA更加智能识别javascript的方法. 测试时的目录结构,一种典型的 thinkphp 的结构,同时,在 a.thml 中通过 req ...