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

AI Hentai Generator
Generate AI Hentai for free.

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



In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

To fill in the MySQL username and password: 1. Determine the username and password; 2. Connect to the database; 3. Use the username and password to execute queries and commands.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

Detailed explanation of database ACID attributes ACID attributes are a set of rules to ensure the reliability and consistency of database transactions. They define how database systems handle transactions, and ensure data integrity and accuracy even in case of system crashes, power interruptions, or multiple users concurrent access. ACID Attribute Overview Atomicity: A transaction is regarded as an indivisible unit. Any part fails, the entire transaction is rolled back, and the database does not retain any changes. For example, if a bank transfer is deducted from one account but not increased to another, the entire operation is revoked. begintransaction; updateaccountssetbalance=balance-100wh

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;
