MySql配置主从复制 读写分离 ? mysql版本:5.6.13 OS:windows server 2008 Master 配置 ? my.ini配置文件中 主从复制需要通过二进制日志文件进行,须开启二进制日志功能并配置Server ID ? [mysqld]log-bin=mysql-binserver-id=1 server-id 为1-2 32 ? -1 ? 之
MySql配置主从复制 读写分离?
mysql版本:5.6.13
OS:windows server 2008
Master 配置
?
my.ini配置文件中
主从复制需要通过二进制日志文件进行,须开启二进制日志功能并配置Server ID
?
[mysqld] log-bin=mysql-bin server-id=1
server-id 为1-232?-1? 之间,默认为0(拒绝所有slave)
?
innodb引擎耐用性增强
innodb_flush_log_at_trx_commit=1?and?sync_binlog=1
?
For the greatest possible durability and consistency in a replication setup using?InnoDB
?with transactions, you should use?innodb_flush_log_at_trx_commit=1
?and?sync_binlog=1
?in the master?my.cnf
?file.
?
?slave 配置
server-id=2
防止服务器主机名修改
?relay-log=mysqld-relay-bin
?
master
创建具有复制权限的账户repl
GRANT REPLICATION SLAVE ON *.*
-> TO 'repl'@'remotehost.mydomain.com' IDENTIFIED BY 'slavepass';
?
<span><span><span>mysql> </span></span><strong class="userinput"><code ><span><span>FLUSH TABLES WITH READ LOCK;</span></span></code></strong></span>
对于<span><span>InnoDB</span></span>
表的注意?<span><span>FLUSH TABLES WITH READ LOCK</span></span>
块?<span><span>COMMIT</span></span>
操作。
保留客户端发出?<span><span>FLUSH TABLES</span></span>
语句运行,这样,读锁仍然有效。如果你退出客户端,该锁被释放。
?
?
?
使用?<span><span>SHOW MASTER STATUS</span></span>
语句来确定当前的二进制日志文件的名称和位置:
?
<span><span><span>的mysql> </span></span><strong class="userinput"><code ><span><span>SHOW MASTER STATUS;</span></span></code></strong></span><span><span> <span>+ ------------------ + ---------- + -------------- + ---- -------------- +</span></span></span><span><span> <span>|“文件”|“位置| Binlog_Do_DB | Binlog_Ignore_DB |</span></span></span><span><span> <span>+ ------------------ + ---------- + -------------- + ---- -------------- +</span></span></span><span><span> <span>MYSQL-bin.000003 | 73 |测试|说明书,MYSQL |</span></span></span><span><span> <span>+ ------------------ + ---------- + -------------- + ---- -------------- +</span></span></span>
?
<span><span>文件</span></span>
栏显示的日志文件的名称和<span><span>位置</span></span>
显示在文件中的位置。在这个例子中,二进制日志文件是?<span><span>mysql-bin.000003的</span></span>
位置是73。记录这些值。你需要它们,以后当你设立的奴隶。他们表示复制坐标奴隶从主应该开始处理新的更新。
?
如果主已经运行以前没有二进制日志启用,通过<span><span>SHOW MASTER STATUS</span></span>
或mysqldump的-主数据显示日志文件的名称和位置值将是空的。在这种情况下,你需要使用指定的奴隶的日志文件和位置后的值是空字符串(<span><span>''</span></span>
)和<span><span>4</span></span>
。
?
你现在有你需要的信息,可以让从开始读取的二进制日志在正确的位置开始复制。
?
设置主从连接信息
?
mysql> <span><strong class="userinput"><code >CHANGE MASTER TO</code></strong> -> <strong class="userinput"><code >MASTER_HOST='<em class="replaceable"><code >master_host_name</code></em>',</code></strong> -> <strong class="userinput"><code >MASTER_USER='<em class="replaceable"><code >replication_user_name</code></em>',</code></strong> -> <strong class="userinput"><code >MASTER_PASSWORD='<em class="replaceable"><code >replication_password</code></em>',</code></strong> -> <strong class="userinput"><code >MASTER_LOG_FILE='<em class="replaceable"><code >recorded_log_file_name</code></em>',</code></strong> -> <strong class="userinput"><code >MASTER_LOG_POS=<em class="replaceable"><code >recorded_log_position</code></em>;</code></strong></span>
查看连接状态 show slave status\G;
?
?读写分离配置
windows设置PATH?
?
创建代理 222为Master 223为只读
?
<span><strong class="userinput"><code >sc create "Proxy" DisplayName= "MySQL Proxy" start= "auto" binPath= "F:\tool\mysql-proxy-0.8.2-winx64-x86\bin\mysql-proxy-svc.exe --proxy-address=localhost:3306 --proxy-backend-addresses=10.133.10.222:3306 --proxy-read-only-backend-addresses=10.133.10.223:3306" </code></strong></span>
?
<strong class="userinput"><code ><span>net start proxy</span></code></strong>
C:\> <strong class="userinput"><code ><span>sc delete proxy</span></code></strong>
配置完之后测试,从服务器 stop slava
通过代理进行insert操作,在进行查询。然后start slave ,主从复制没有问题。
读写分离暂时还未测试

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.

To monitor the health and performance of MySQL servers, you should pay attention to system health, performance metrics and query execution. 1) Monitor system health: Use top, htop or SHOWGLOBALSTATUS commands to view CPU, memory, disk I/O and network activities. 2) Track performance indicators: monitor key indicators such as query number per second, average query time and cache hit rate. 3) Ensure query execution optimization: Enable slow query logs, record and optimize queries whose execution time exceeds the set threshold.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
