MySql配置主从复制 读写分开
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 ,主从复制没有问题。
读写分离暂时还未测试

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting
