Home Database Mysql Tutorial MySQL性能优化的一些技巧帮助你的数据库

MySQL性能优化的一些技巧帮助你的数据库

Jun 07, 2016 pm 05:55 PM
mysql performance mysql performance optimization

你完成了你的品牌新的应用程序,一切工作就像一个魅力;突然间,一个大爆发的用户杀死你的MySQL服务器,您的网站已关闭,是什么问题导致的呢?以下是MySQL性能优化的一些技巧,将帮助你,帮助你的数据库

你完成了你的品牌新的应用程序,一切工作就像一个魅力。用户来使用你的网络。每个人是幸福的。
然后,突然间,一个大爆发的用户杀死你的MySQL服务器,您的网站已关闭。出了什么问题?你怎么能阻止它吗?
以下是MySQL性能优化的一些技巧,将帮助你,帮助你的数据库。

大处着眼
在早期的发展阶段,你应该知道预期到您的应用程序的用户数。如果你希望很多用户来说,你应该想想大,从一开始,计划进行复制,可扩展性和性能。
但是,如果你优化你的SQL代码,架构和索引策略,也许你不会需要大环境。你必须总是三思而后行的性能和可扩展性是不一样的。

请务必使用EXPLAIN
EXPLAIN语句可以被用来作为获取信息的方式MySQL如何执行SELECT语句的代名词DESCRIBE。
当你前面一个关键字EXPLAIN SELECT语句,MySQL的显示信息的查询执行计划的优化。也就是说,MySQL的说明它将如何处理SELECT,包括信息表加入的顺序。可以使用EXPLAIN扩展的提供额外的信息。

选择正确的数据类型
通常存储在磁盘上(除了一些数据库,内存数据库一样,它是存储在内存中)。这意味着,为了获取信息,为您的数据库,它必须从磁盘读取该信息,并把它变成一个结果集,您可以使用。磁盘I / O是极其缓慢的,尤其是在比较其他形式的数据存储。
当你的数据库的增长要大,开始读取时间要长。设计拙劣的数据库处理这个问题比他们实际需要的磁盘上分配更多的空间。这意味着该数据库占用空间的磁盘的使用效率低下。
选择正确的数据类型,可以帮助确保我们存储的数据,使数据库尽可能的小。为此,我们只选择我们所需要的数据类型。

使用持久连接
使用永久连接的原因是减少数量的连接是相当昂贵的,即使他们更快的与MySQL与大多数其他数据库。
有一些争论这个话题,在网络上mysqli扩展已禁用持久性连接功能,所以我会写更多关于这个主题。持久连接的唯一的缺点是,如果你有多个并发连接,可以达到max_connections设置。这是很容易改变Apache的设置,所以我不认为这是原因为什么你不应该使用持久连接。

持久连接是特别有用的,如果你有另一台计算机上的数据库服务器。由于上述缺点,明智地使用它们。

了解查询缓存
查询缓存存储的SELECT语句的文本,连同相应的结果发送到客户端。如果相同的语句被接收后,服务器从查询缓存中,而不是分析和再次执行该语句检索结果。查询缓存是共享的会话之间,这样的结果集所产生的一个客户端可以发送另一个客户端发出的相同的查询。

查询缓存的环境中,可能是有用的,你有表不经常改变,服务器接收到许多相同的查询。对于许多Web服务器产生许多动态页面的基于数据库的内容,这是一个典型的情况。

查询缓存不返回过时的数据。在查询缓存表被修改时,任何相关的条目将被刷新。

你怎么找到我的MySQL查询缓存是工作或没有?
MySQL提供的统计资料,只需键入下面的命令在mysql>提示符下:
代码如下:
mysql> show variables like 'query%';

不要使用索引列的功能
列上的索引可以是伟大的性能增益,但如果你使用该列中的函数,指数是从来没有使用过。
总是尝试重写查询不使用索引列的功能。
代码如下:
WHERE TO_DAYS(CURRENT_DATE) - TO_DAYS(event_date)
可能是
代码如下:
WHERE event_date >= '2011/03/15' - INTERVAL 7 DAYS

今天的日期是从PHP生成。这样一来,指数列EVENT_DATE的查询缓存内可存储和查询。
了解禅宗的SQL编码
SQL代码是优化数据库性能的基础。主SQL编码技术,如重写子查询的SQL语句使用连接,消除了连接和类似的游标。
通过编写巨大SQL代码数据库的性能将是巨大的。
使用ON DUPLICATE KEY UPDATE
如果你指定ON DUPLICATE KEY UPDATE,将某行插入,会导致在一个UNIQUE索引或PRIMARY KEY重复的值,更新旧行。
代码如下:
INSERT INTO wordcount (word, count) VALUES ('a_word',1) ON DUPLICATE KEY UPDATE count=count+1;

您保存访问服务器(然后选择更新),清理你的代码删除所有,如果record_exists插入其他更新。
如果按照此提示,数据库将不胜感激给你。
Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize MySQL connection speed? How to optimize MySQL connection speed? Jun 29, 2023 pm 02:10 PM

How to optimize MySQL connection speed? Overview: MySQL is a widely used relational database management system that is commonly used for data storage and management in a variety of applications. During development, optimization of MySQL connection speed is critical to improving application performance. This article will introduce some common methods and techniques for optimizing MySQL connection speed. Table of Contents: Use connection pools to adjust connection parameters and optimize network settings. Use indexing and caching to avoid long idle connections. Configure appropriate hardware resources. Summary: Use connection pools.

How to optimize the performance of SQL Server and MySQL so that they can perform at their best? How to optimize the performance of SQL Server and MySQL so that they can perform at their best? Sep 11, 2023 pm 01:40 PM

How to optimize the performance of SQLServer and MySQL so that they can perform at their best? Abstract: In today's database applications, SQLServer and MySQL are the two most common and popular relational database management systems (RDBMS). As the amount of data increases and business needs continue to change, optimizing database performance has become particularly important. This article will introduce some common methods and techniques for optimizing the performance of SQLServer and MySQL to help users take advantage of

Analysis of project experience on MySQL database backup and recovery performance optimization Analysis of project experience on MySQL database backup and recovery performance optimization Nov 02, 2023 am 08:53 AM

In the current Internet era, the importance of data is self-evident. As one of the core components of Internet applications, database backup and recovery work is particularly important. However, as the amount of data continues to increase and business requirements become increasingly complex, traditional database backup and recovery solutions can no longer meet the high availability and high performance requirements of modern applications. Therefore, optimizing the backup and recovery performance of MySQL database has become an urgent problem that needs to be solved. In practice, we have adopted a series of project experiences to effectively improve MySQL data

How to improve MySQL performance by using composite indexes How to improve MySQL performance by using composite indexes May 11, 2023 am 11:10 AM

In the MySQL database, indexing is a very important means of performance optimization. When the amount of data in the table increases, inappropriate indexes can cause queries to slow down or even cause database crashes. In order to improve database performance, indexes need to be used rationally when designing table structures and query statements. Composite index is a more advanced indexing technology that improves query efficiency by combining multiple fields as indexes. In this article, we will detail how to improve MySQL performance by using composite indexes. What is composite index composite

MySQL performance optimization practical guide: in-depth understanding of B+ tree indexes MySQL performance optimization practical guide: in-depth understanding of B+ tree indexes Jul 25, 2023 pm 08:02 PM

MySQL Performance Optimization Practical Guide: In-depth Understanding of B+ Tree Indexes Introduction: As an open source relational database management system, MySQL is widely used in various fields. However, as the amount of data continues to increase and query requirements become more complex, MySQL's performance problems are becoming more and more prominent. Among them, the design and use of indexes are one of the key factors affecting MySQL performance. This article will introduce the principle of B+ tree index and show how to optimize the performance of MySQL with actual code examples. 1. Principle of B+ tree index B+ tree is a

How to use PHP's PDO class to optimize MySQL performance How to use PHP's PDO class to optimize MySQL performance May 10, 2023 pm 11:51 PM

With the rapid development of the Internet, MySQL database has become the core data storage technology for many websites, applications and even enterprises. However, with the continuous growth of data volume and the sharp increase in concurrent access, MySQL's performance problems have become increasingly prominent. PHP's PDO class is also widely used in the development and operation of MySQL because of its efficient and stable performance. In this article, we will introduce how to use the PDO class to optimize MySQL performance and improve the database's response speed and concurrent access capabilities. 1. Introduction to PDO class

How to improve MySQL performance with transaction isolation levels How to improve MySQL performance with transaction isolation levels May 11, 2023 am 09:33 AM

In MySQL, transaction isolation level is a very important concept, which determines how the database handles concurrent access to data when multiple transactions are executed at the same time. In practical applications, we need to choose the appropriate isolation level based on specific business needs to improve the performance of MySQL. First, we need to understand MySQL’s four transaction isolation levels: READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ and SERIALIZA

How to improve MySQL performance by using dynamic SQL statements How to improve MySQL performance by using dynamic SQL statements May 11, 2023 am 09:28 AM

In modern applications, the MySQL database is a common choice. However, as data volumes grow and business needs continue to change, MySQL performance may suffer. In order to maintain the high performance of MySQL database, dynamic SQL statements have become an important technical means to improve the performance of MySQL. What is a dynamic SQL statement? A dynamic SQL statement refers to the technology of generating SQL statements by a program in an application. In layman's terms, it means treating SQL statements as strings. For large applications,

See all articles