MariaDB单机双实例主从复制,MariaDB其实和MySQL一样,非有啥不一样那就是名字不一样。
MariaDB单机双实例主从复制
MariaDB其实和MySQL一样,非有啥不一样那就是名字不一样。
开始~上篇实验是MariaDB的单机多实例安装
双实例端口3307主库,,3308从库
3307主实例的mysqld配置
[mysqld2]
port=3307
socket=/tmp/mysql3307.sock
pid-file=/tmp/mysql3307.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/mydata2
server-id=244
log-bin = master3307-bin
log-bin-index = master3307-bin.index
thread_concurrency=4
innodb_file_per_table = 1
#mysql_pwd='teleframe'
3308从实例的mysqld配置
[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
开始主从配置
步骤1、连接到主库上授权一个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)]>
2、连接到从库上指定主库,启动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:
来测试!
在主的上面创建一个库看从的是否可以复制到
主上创建

MySQL索引基数对查询性能有显著影响:1.高基数索引能更有效地缩小数据范围,提高查询效率;2.低基数索引可能导致全表扫描,降低查询性能;3.在联合索引中,应将高基数列放在前面以优化查询。

MySQL學習路徑包括基礎知識、核心概念、使用示例和優化技巧。 1)了解表、行、列、SQL查詢等基礎概念。 2)學習MySQL的定義、工作原理和優勢。 3)掌握基本CRUD操作和高級用法,如索引和存儲過程。 4)熟悉常見錯誤調試和性能優化建議,如合理使用索引和優化查詢。通過這些步驟,你將全面掌握MySQL的使用和優化。

MySQL在現實世界的應用包括基礎數據庫設計和復雜查詢優化。 1)基本用法:用於存儲和管理用戶數據,如插入、查詢、更新和刪除用戶信息。 2)高級用法:處理複雜業務邏輯,如電子商務平台的訂單和庫存管理。 3)性能優化:通過合理使用索引、分區表和查詢緩存來提升性能。

MySQL中的SQL命令可以分為DDL、DML、DQL、DCL等類別,用於創建、修改、刪除數據庫和表,插入、更新、刪除數據,以及執行複雜的查詢操作。 1.基本用法包括CREATETABLE創建表、INSERTINTO插入數據和SELECT查詢數據。 2.高級用法涉及JOIN進行表聯接、子查詢和GROUPBY進行數據聚合。 3.常見錯誤如語法錯誤、數據類型不匹配和權限問題可以通過語法檢查、數據類型轉換和權限管理來調試。 4.性能優化建議包括使用索引、避免全表掃描、優化JOIN操作和使用事務來保證數據一致性

InnoDB通過undolog實現原子性,通過鎖機制和MVCC實現一致性和隔離性,通過redolog實現持久性。 1)原子性:使用undolog記錄原始數據,確保事務可回滾。 2)一致性:通過行級鎖和MVCC確保數據一致。 3)隔離性:支持多種隔離級別,默認使用REPEATABLEREAD。 4)持久性:使用redolog記錄修改,確保數據持久保存。

MySQL在數據庫和編程中的地位非常重要,它是一個開源的關係型數據庫管理系統,廣泛應用於各種應用場景。 1)MySQL提供高效的數據存儲、組織和檢索功能,支持Web、移動和企業級系統。 2)它使用客戶端-服務器架構,支持多種存儲引擎和索引優化。 3)基本用法包括創建表和插入數據,高級用法涉及多表JOIN和復雜查詢。 4)常見問題如SQL語法錯誤和性能問題可以通過EXPLAIN命令和慢查詢日誌調試。 5)性能優化方法包括合理使用索引、優化查詢和使用緩存,最佳實踐包括使用事務和PreparedStatemen

MySQL適合小型和大型企業。 1)小型企業可使用MySQL進行基本數據管理,如存儲客戶信息。 2)大型企業可利用MySQL處理海量數據和復雜業務邏輯,優化查詢性能和事務處理。

InnoDB通過Next-KeyLocking機制有效防止幻讀。 1)Next-KeyLocking結合行鎖和間隙鎖,鎖定記錄及其間隙,防止新記錄插入。 2)在實際應用中,通過優化查詢和調整隔離級別,可以減少鎖競爭,提高並發性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

記事本++7.3.1
好用且免費的程式碼編輯器