bitsCN.com
与小站点相比,大型站点的数据库管理员,需要提前做好以下的事情:
提供灾难发生时核心业务数据的恢复计划。理论上这个过程至少需要执行一次。
通过采集大量用户数据并监控网站各节点的负载,提供优化计划
当用户数量急剧增长时的快速横向扩展计划
对于所有这些事情,提前计划并准备好必要时的快速应对是很重要的。
为了保证站点可响应和可用性,需要做两件事:系统的数据备份和冗余。备份可以将节点恢复到它崩溃之前的状态,备份根据需求有几种比如及时恢复(PITR:point-in-time-recovery),在线备份等等;而冗余则保证即使在一个或更多节点停止服务的情况下,站点仍能继续运行,备份一般通过硬件副本来实现,让几个实例并行运行,并通过复制在几个机器上保存相同数据的多个可用副本。复制的主要应用场景:1)针对高读写比的,scale out;2)添加冗余保证高可用性,比如双主配置(dual-master setup)。
二进制日志(binlog)
复制过程需要二进制日志。二进制日志的目的是记录数据库中表的更改,然后用于复制和PITR,另外少数审计情况下也会用到。
传统意义上说,MySQL复制记录了产生变化的SQL语句,称为基于语句的复制(statement-based replication)。基于语句的复制的缺点是无法保证所有语句都正确复制。所以在5.1版本中,MySQL还提供了基于行的复制(row-based replication)。
查看二进制日志:
# 强制把缓存的东西刷到LOGS中,并产生一个Rotate事件写入binlog中FLUSH LOGS;# 正常使用很久的DB不建议使用这个命令,需要加参数,指定具体的binlog文件名 【IN 'xxxx'】SHOW BINLOG EVENTS/G
二进制日志中事件所包含的字段:
Event_type: 比如Format_desc, Query, RotateServer_id : 创建事件的服务器idLog_name : 存储事件的文件名,一个事件只能存储在一个文件中Pos : 事件在文件中的开始位置,及事件的第一个字节End_log_pos:事件在文件中的结束位置,也就是下一个事件的开始位置Info : 具体事件的信息,Query的时候就是SQL语句
二进制日志的结构和内容:
二进制日志不是一个的单独的文件,它包括一组存储实际内容的二进制日志文件和一个二进制日志索引文件。每个二进制日志文件都以format description event开始,以rotate event结束。rotate event包含下一个二进制日志文件的名称,以告知二进制日志继续写入哪个文件。因此FLUSH LOGS的时候会新建一个新binlog文件。
获取当前正在写入的是哪一个二进制日志文件:
SHOW MASTER STATUS/G
RESET MASTER命令删除了所有的二进制日志文件并清空了二进制日志索引文件。RESET SLAVE命令删除了Slave复制所用的所有文件,重新开始。
CHANGE MASTER TO命令用于改变slave连接master的一些参数,其中就包括slave读取master二进制日志文件的参数。比如使用MASTER_LOG_FILE和MASTER_LOG_POS来指定master开始发送事件的binlog位置。
如何建立新Slave
1:配置新的Slave2:备份Master(或者备份已经复制了Master的Slave)3:接下该备份相应的binlog位置4:在新Slave上恢复备份5:配置Slave从这个binlog位置开始复制
区别就在于第二步,一种是直接从Master进行备份,一种是通过现有Slave备份,下面分别介绍两种。
1:克隆Master:
# 刷新所有的表并锁定数据库,防止在检查binlog位置之前数据库发生改变FLUSH TABLES WITH READ LOCK;# 获取当前的binlog文件和posSHOW MASTER STATUS/G# 备份mastermysqldump --all-databases --host=master-1 >backup.sql# 解锁UNLOCK TABLES;# 在slave上恢复备份mysql --host=slave-1 其实mysqldump命令提供了master_data选项,自动把MASTER_LOG_FILE和MASTER_LOG_POS信息dump到backup.sql中 另外:FLUSH TABLES WITH READ LOCK对于InnoDB是不安全的,因为虽然会锁表,不会产生新事务,但是后台仍然有一些活动在继续进行。 所以安全的创建InnoDB数据表的备份可以使用下面的方法。 1:关闭服务器,然后复制文件。如果数据库很大 ,最好采取这种方法,因为这时使用mysqldump进行数据恢复会很慢2:执行FLUSH TABLES WITH READ LOCK之后,使用mysqldump3:执行FLUSH TABLES WITH READ LOCK之后,使用快照的方法,比如LVM(Linux),ZFS(Solaris)快照 2:克隆Slave: # 防止出现不一致的备份映像,备份Slave之前需要先停止replicationSTOP SLAVE;# 确定从哪里开始复制,注意Relay_Master_Log_File和Exec_Master_Log_PosSHOW SLAVE STATUS/G# 配置新的slave,指向masterCHANGE MASTER TOMASTER_HOST = 'master-1',MASTER_PORT = 3306,MASTER_USER = 'slave-1',MASTER_PASSWORD = 'xxxx',MASTER_LOG_FILE = 'master-bin.000042',MASTER_LOG_POS = 546632;# 启动新的slaveSTART SLAVE 摘自 foxracle

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.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment