MariaDB其实和mysql同样,非有啥不同那就是名字不同~.~!mysql
开始~上篇实验是MariaDB的单机多实例安装sql
复制一般用来建立主节点的副本,经过添加冗余节点来保证高可用性,固然复制也能够用于其余用途,例如在从节点上进行数据读、分析等等。在横向扩展的业务中,复制很容易实施,主要表如今在利用主节点进行写操做,多个从节点进行读操做,mysql复制的异步性是指:事物首先在主节点上提交,而后复制给从节点并在从节点上应用,这样意味着在同一个时间点主从上的数据可能不一致,异步复制的好处在于它比同步复制要快,若是对数据的一致性要求很高,仍是采用同步复制较好。shell
最简单的复制模式就是一主一从的复制模式了,这样一个简单的架构只须要三个步骤便可完成:数据库
1 创建一个主节点,开启binlog,设置服务器id缓存
2 创建一个从节点,设置服务器id服务器
3 将从节点链接到主节点上架构
双实例端口3307主库,3308从库异步
3307主实例的mysqld配置socket
[mysqld2] port=3307 socket=/tmp/mysql3307.sock #套接字文件 pid-file=/tmp/mysql3307.pid #PID文件目录 max_allowed_packet=1M #容许插入的数据大小 net_buffer_length=2k #套接字通讯缓冲区大小 table_open_cache=4 #表告诉缓存的大小 sort_buffer_size=64k #排序buffer大小 thread_stack=128k #每个线程分配多大内存 basedir=/usr/local/mysql #多实例必须开启的安装数据库目录 datadir=/data/mydata2 #数据目录 server-id=244 #主从复制ID必须不同 log-bin = master3307-bin #必须开启 log-bin-index = master3307-bin.index #必须开启 thread_concurrency=4 #4个线程 innodb_file_per_table = 1 #每表一空间 #mysql_pwd='teleframe'
3308从实例的mysqld配置ide
[mysqld3] port=3308 socket=/tmp/mysql3308.sock pid-file=/tmp/mysql3308.pid max_allowed_packet=1M net_buffer_length=2k table_open_cache=4 sort_buffer_size=64k thread_stack=128k basedir=/usr/local/mysql datadir=/data/mydata3 innodb_file_per_table = 1 server-id=245 log-bin=mysql3308-bin relay-log = relay-log relay-log-index = relay-log-index thread_concurrency=4 read-only = on
开始主从配置
步骤一、链接到主库上受权一个REPLICATION SLAVE
账号,而且刷新受权表
[root@e3 mysql]# mysql -uroot -h127.0.0.1 -P3307 -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.0.15-MariaDB-log Source distribution Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | test1 | +--------------------+ 5 rows in set (0.00 sec) MariaDB [(none)]> grant replication slave on *.* to 'repl'@'192.168.0.%' identified by 'repl'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show master status; +-----------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-----------------------+----------+--------------+------------------+ | master3307-bin.000005 | 632 | | | +-----------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) MariaDB [(none)]>
二、链接到从库上指定主库,启动slave
[root@e3 ~]# mysql -uroot -p'teleframe' -h127.0.0.1 -P3308 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.0.15-MariaDB-log Source distribution Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> change master to master_host='192.168.0.244',master_user='repl',master_password='repl',master_port=3307,master_log_file='master3307-bin.000005',master_log_pos=632; ERROR 1201 (HY000): Could not initialize master info structure for ''; more error messages can be found in the MariaDB error log #我这报错了,若是你跟我同样报错就执行下面的命令 MariaDB [(none)]> reset slave; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> change master to master_host='192.168.0.244',master_user='repl',master_password='repl',master_port=3307,; Query OK, 0 rows affected (0.22 sec) #好了如今链接上了 master_log_file='master3307-bin.000005',master_log_pos=632 表示从主服务器那个二进制日志文件开始复制由于这是复制受权信息,因此不必复制,在主服务器上能够查看show master status; 查看内容show binglog events in 'master-bin.000001'; MariaDB [(none)]> show slave status\G *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.0.244 Master_User: repl Master_Port: 3307 Connect_Retry: 60 Master_Log_File: master3307-bin.000005 Read_Master_Log_Pos: 632 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 4 Relay_Master_Log_File: master3307-bin.000005 Slave_IO_Running: No # 从服务器有没有正常工做主要是看这个值是否YES Slave_SQL_Running: No # 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: 632 Relay_Log_Space: 248 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: NULL 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: 0 Master_SSL_Crl: Master_SSL_Crlpath: Using_Gtid: No Gtid_IO_Pos: 1 row in set (0.00 sec) MariaDB [(none)]> start slave; #好启动slave Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.0.244 Master_User: repl Master_Port: 3307 Connect_Retry: 60 Master_Log_File: master3307-bin.000005 Read_Master_Log_Pos: 632 Relay_Log_File: relay-log.000003 Relay_Log_Pos: 540 Relay_Master_Log_File: master3307-bin.000005 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: 632 Relay_Log_Space: 831 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: 244 Master_SSL_Crl: Master_SSL_Crlpath: Using_Gtid: No Gtid_IO_Pos:
来测试!
在主的上面建立一个库看从的是否能够复制到
主上建立
MariaDB [(none)]> create database kcwtest; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | kcwtest | | mysql | | performance_schema | | test | | test1 | +--------------------+ 6 rows in set (0.00 sec)
从上查看
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | kcwtest | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec)
能够复制!这样就实现单机实例复制,我作的3个实例,3306端口给默认的用,3307,3308端口作主从复制。