search
HomeDatabaseMysql Tutorial 浅谈MySQL学习及思考

浅谈MySQL学习及思考

Jun 07, 2016 pm 05:40 PM
mysql optimizationmysql designraid

本博文旨在结合自己看书理解,并借此图进行说明,如有谬误,望大家指正,以共同探讨为目的,交流学习。首先介绍一下架构图的由来:最近看关于mysql方面书籍的一点

 本博文旨在结合自己看书理解,并借此图进行说明,如有谬误,望大家指正,以共同探讨为目的,交流学习。

首先介绍一下架构图的由来:最近看关于mysql方面书籍的一点心得,把文字转化成图片而得,方便理解。

 

我主要从读、写、底层磁盘三方面进行阐述:

1、读操作:

  我们知道数据在读取的时候,需要从磁盘读到内存中,然后再做相应的操作,而在优化读操作的时候,主要想buffer,cache这些进行优化:

  以上是读操作的一些介绍,接下来是写操作方面的。

2、写操作:

  写操作分为热门数据和普通数据,简而言之就是按照频繁程度进行划分的。然频繁修改的数据可以和非频繁的数据进行分开。

举个例子:

  • 比如我网站每天PV 1000w,而在PV统计的表中,我每次访问就会插入一条数据,一天下来1000w,当然这还不可能是分摊在24小时,就按照10个小时的中高峰期来说,每个小时也是100w条数据,如果我的网站其他表中的跟新的数据每天2w条,相对1000w来说,就是太少了,但是这2w条数据有事比较重要的数据,如果是用户注册、客户购买商品下的订单,他可比记录PV信息更重要吧,这时候问题就出现了:我的热门数据究竟是什么?是PV统计还是订单、注册用户,不言而喻,当然其中一个还是重点数据了,所以为了不让记录PV的数据来影响更重要的数据的更新,我们可以把他分开,如果后面还有主从同步的话,分开后,同步的负载也会降低很多,这样就可以只同步2w条数据,香港空间,而不用考虑那1000w条数据了,服务器空间,进而主数据库的负载也会降低。 
  •   现在是把热门数据和普通数据分开了,但是对于高并发的数据库服务器来说,如何抗并发,这到成了一个重要的问题,当然高配服务器,集群用上,包括Nosql也用上可一解决这样的问题,如果在设计的时候能使用队列机制,这样不就更好了嘛!(地铁上看到一句广告语:有序方能通畅!)

      当然你可能有更好的方法,香港虚拟主机,可以共同交流。

    3、底层磁盘规划:

     

     

     

  • RAID6: 
  • RADI6技术是在RAID5基础上,为了进一步加强数据保护而设计的一种RAID方式,实际上是一种扩展RAID5等级。与RAID5的不同之处于除了每个硬盘上都有同级数据XOR校验区外,还有一个针对每个数据块的XOR校验区。当然,当前盘数据块的校验数据不可能存在当前盘而是交错存储的,具体形式见图。这样一来,等于每个数据块有了两个校验保护屏障(一个分层校验,一个是总体校验),因此RAID6的数据冗余性能相当好。但是,由于增加了一个校验,所以写入的效率较RAID5还差,而且控制系统的设计也更为复杂,第二块的校验区也减少了有效存储空间。 
  •  

      而对于热门数据可以使用RAID10,这样他的性能和安全性会提高很多;而普通数据可以采用RAID5,主要提供安全性,像临时表这样的使用RAID0,在性能上发挥巨大的优势。

    以上均个人见解,如有疑问,可共同交流学习!

     

    本文出自 “Ro の博客” 博客,请务必保留此出处

    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

    MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

    MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

    ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

    MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

    ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

    MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

    MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

    MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

    Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

    Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

    Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

    Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

    ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

    MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

    Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

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

    Hot Article

    Hot Tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    mPDF

    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),