Home Database Mysql Tutorial 8个MySQL性能优化技巧_MySQL

8个MySQL性能优化技巧_MySQL

Jun 01, 2016 pm 01:36 PM
app Skill server website network

bitsCN.com

8个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插入其他更新。

 

如果按照此提示,数据库将不胜感激给你。

bitsCN.com
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

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months 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 connect Apple Vision Pro to PC How to connect Apple Vision Pro to PC Apr 08, 2024 pm 09:01 PM

The Apple Vision Pro headset is not natively compatible with computers, so you must configure it to connect to a Windows computer. Since its launch, Apple Vision Pro has been a hit, and with its cutting-edge features and extensive operability, it's easy to see why. Although you can make some adjustments to it to suit your PC, and its functionality depends heavily on AppleOS, so its functionality will be limited. How do I connect AppleVisionPro to my computer? 1. Verify system requirements You need the latest version of Windows 11 (Custom PCs and Surface devices are not supported) Support 64-bit 2GHZ or faster fast processor High-performance GPU, most

Shazam app not working in iPhone: Fix Shazam app not working in iPhone: Fix Jun 08, 2024 pm 12:36 PM

Having issues with the Shazam app on iPhone? Shazam helps you find songs by listening to them. However, if Shazam isn't working properly or doesn't recognize the song, you'll have to troubleshoot it manually. Repairing the Shazam app won't take long. So, without wasting any more time, follow the steps below to resolve issues with Shazam app. Fix 1 – Disable Bold Text Feature Bold text on iPhone may be the reason why Shazam is not working properly. Step 1 – You can only do this from your iPhone settings. So, open it. Step 2 – Next, open the “Display & Brightness” settings there. Step 3 – If you find that “Bold Text” is enabled

What's going on when the network can't connect to the wifi? What's going on when the network can't connect to the wifi? Apr 03, 2024 pm 12:11 PM

1. Check the wifi password: Make sure the wifi password you entered is correct and pay attention to case sensitivity. 2. Confirm whether the wifi is working properly: Check whether the wifi router is running normally. You can connect other devices to the same router to determine whether the problem lies with the device. 3. Restart the device and router: Sometimes, there is a malfunction or network problem with the device or router, and restarting the device and router may solve the problem. 4. Check the device settings: Make sure the wireless function of the device is turned on and the wifi function is not disabled.

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Mar 27, 2024 pm 02:57 PM

Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

How to Install and Run the Ubuntu Notes App on Ubuntu 24.04 How to Install and Run the Ubuntu Notes App on Ubuntu 24.04 Mar 22, 2024 pm 04:40 PM

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

What are the tips for novices to create forms? What are the tips for novices to create forms? Mar 21, 2024 am 09:11 AM

We often create and edit tables in excel, but as a novice who has just come into contact with the software, how to use excel to create tables is not as easy as it is for us. Below, we will conduct some drills on some steps of table creation that novices, that is, beginners, need to master. We hope it will be helpful to those in need. A sample form for beginners is shown below: Let’s see how to complete it! 1. There are two methods to create a new excel document. You can right-click the mouse on a blank location on the [Desktop] - [New] - [xls] file. You can also [Start]-[All Programs]-[Microsoft Office]-[Microsoft Excel 20**] 2. Double-click our new ex

A must-have for veterans: Tips and precautions for * and & in C language A must-have for veterans: Tips and precautions for * and & in C language Apr 04, 2024 am 08:21 AM

In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

See all articles