mysqlreport显示Com_中change_db占用比例高的问题的解决方法_MySQL
bitsCN.com 首先说明一点,每天的访问量并不大每天才2W的访问量,按道理说,访问量再增加一倍这样的服务器也应该足以承受。可是我们的服务器为什么总是这样频频重启呢?经过mysqlreport显示mysql运行的状态如下:
<pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><pre class="brush:php;toolbar:false"><font color="#006bad">MySQL 5.1.28-rc-log uptime 0 0:4:48 Thu Apr 30 14:04:58 2009<br><br>__ Key _________________________________________________________________<br>Buffer used 7.74M of 384.00M %Used: 2.02<br> Current 52.89M %Usage: 13.77<br>Write hit 0.00%<br>Read hit 91.97%<br><br>__ Questions ___________________________________________________________<br>Total 14.46k 50.2/s<br> DMS 9.24k 32.1/s %Total: 63.90<br> QC Hits 3.66k 12.7/s 25.33<br> Com_ 1.04k 3.6/s 7.19<br> COM_QUIT 517 1.8/s 3.58<br> -Unknown 1 0.0/s 0.01<br>Slow 1 s 4 0.0/s 0.03 %DMS: 0.04 Log: OFF<br>DMS 9.24k 32.1/s 63.90<br> SELECT 9.21k 32.0/s 63.75 99.75<br> UPDATE 23 0.1/s 0.16 0.25<br> REPLACE 0 0/s 0.00 0.00<br> DELETE 0 0/s 0.00 0.00<br> INSERT 0 0/s 0.00 0.00<br>Com_ 1.04k 50/s 44.4<br> set_option 523 1.8/s 3.62<br> change_db 510 50/s 44.4<br> show_proces 5 0.0/s 0.03<br><br>__ SELECT and Sort _____________________________________________________<br>Scan 49 0.2/s %SELECT: 0.53<br>Range 16 0.1/s 0.17<br>Full join 2 0.0/s 0.02<br>Range check 0 0/s 0.00<br>Full rng join 0 0/s 0.00<br>Sort scan 55 0.2/s<br>Sort range 475 1.6/s<br>Sort mrg pass 0 0/s<br><br>__ Query Cache _________________________________________________________<br>Memory usage 12.02M of 150.00M %Used: 8.01<br>Block Fragmnt 0.01%<br>Hits 3.66k 12.7/s<br>Inserts 9.14k 31.8/s<br>Insrt:Prune 9.14k:1 31.8/s<br>Hit:Insert 0.40:1<br><br>__ Table Locks _________________________________________________________<br>Waited 0 0/s %Total: 0.00<br>Immediate 10.49k 36.4/s<br><br>__ Tables ______________________________________________________________<br>Open 58 of 512 %Cache: 11.33<br>Opened 64 0.2/s<br><br>__ Connections _________________________________________________________<br>Max used 4 of 2000 %Max: 0.20<br>Total 519 1.8/s<br><br>__ Created Temp ________________________________________________________<br>Disk table 1 0.0/s<br>Table 184 0.6/s Size: 256.0M<br>File 5 0.0/s<br><br>__ Threads _____________________________________________________________<br>Running 2 of 2<br>Cached 2 of 150 %Hit: 99.23<br>Created 4 0.0/s<br>Slow 0 0/s<br><br>__ Aborted _____________________________________________________________<br>Clients 0 0/s<br>Connects 0 0/s<br><br>__ Bytes _______________________________________________________________<br>Sent 20.36M 70.7k/s<br>Received 1.37M 4.7k/s<br><br>__ InnoDB Buffer Pool __________________________________________________<br>Usage 304.00k of 8.00M %Used: 3.71<br>Read hit 84.42%<br>Pages<br> Free 493 %Total: 96.29<br> Data 19 3.71 %Drty: 0.00<br> Misc 0 0.00<br> Latched 0.00<br>Reads 77 0.3/s<br> From file 12 0.0/s 15.58<br> Ahead Rnd 1 0.0/s<br> Ahead Sql 0 0/s<br>Writes 0 0/s<br>Flushes 0 0/s<br>Wait Free 0 0/s<br><br>__ InnoDB Lock _________________________________________________________<br>Waits 0 0/s<br>Current 0<br>Time acquiring<br> Total 0 ms<br> Average 0 ms<br> Max 0 ms<br><br>__ InnoDB Data, Pages, Rows ____________________________________________<br>Data<br> Reads 25 0.1/s<br> Writes 3 0.0/s<br> fsync 3 0.0/s<br> Pending<br> Reads 0<br> Writes 0<br> fsync 0<br><br>Pages<br> Created 0 0/s<br> Read 19 0.1/s<br> Written 0 0/s<br><br>Rows<br> Deleted 0 0/s<br> Inserted 0 0/s<br> Read 0 0/s<br> Updated 0 0/s<br>大家可以看到在Com_中占的比例是相当大的,而一般情况下,这个值应该是3.0%左右。如果这个值过高的话,就说明,你的mysql处理请求中<br>做了一些无谓的工作,占用了大量的系统资源。其中我们看到尤为change_db的占用率比较高。这个值高了,说明我们执行的user database;命令相当多。<br>检查程序,原来我们在执行查询语句的时候应用了mysql_query_db("database","sql");这个语句在每次执行的时候都会自动调用use database;<br>所以我们应该将mysql_db_query 更改成mysql_query();再观察mysql的运行状态,ok。一切正常了。</font>

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

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
