MySQL database leads to high CPU problem resolution

Source: Internet
Author: User
Tags character set mysql query php code mysql database

Server environment Liunx AS4 + PHP5 + Mysql5 + Apache 2

The utility top command queries system performance to find that the CPU often reaches 100%

Started thinking it was a DDoS attack ... Firewall installed (not working)

Start looking for a system problem from the LIUNX system (and it doesn't work)

Occasionally, an article was found on the web, and some people were similarly confronted with such a problem, but did not point out the specific solution,

But remind me, not a system problem is a procedural problem!

This time I began to filter the new PHP code, and occasionally found that many of the brothers write code only "often" connection, unexpectedly no close!

I've installed all the pages. Database shutdown, found that the CPU has been kept between the 1%~10% (normal)

So remind everyone in writing PHP program when not for a little lazy, causing the system overflow such low-level errors!

Well, just write it down here, a little problem that took me almost an afternoon to get this! It's a lesson!

Put some mysql commonly used functions affixed, please keep in mind! Other types of databases extrapolate!

Mysql_affected_rows-the number of record rows affected by the previous MySQL operation

Mysql_change_user--Changing the user who is logged on in the active connection

Mysql_client_encoding--Returns the name of the character set

Mysql_close--Close MySQL connection

Mysql_connect--Open a connection to the MySQL server

mysql_create_db--Create a new MySQL database

Mysql_data_seek--A pointer to moving internal results

Mysql_db_name--Get the result data

Mysql_db_query--Send a MySQL query

mysql_drop_db--Discard (delete) a MySQL database

Mysql_errno--numeric code that returns the error message from the previous MySQL operation

Mysql_error-Returns the text error message from the previous MySQL operation

Mysql_escape_string--Escapes a string for mysql_query

Mysql_fetch_array--Take one row from the result set as an associative array, or an array of numbers, or both

MYSQL_FETCH_ASSOC--get one row from the result set as an associative array

Mysql_fetch_field--Get column information from the result set and return as an object

Mysql_fetch_lengths--Gets the length of each output in the result set

Mysql_fetch_object--get one row from the result set as an object

Mysql_fetch_row--get one row from the result set as an enumeration array

Mysql_field_flags--flags that are associated with the specified field from the result

Mysql_field_len--Returns the length of the specified field

Mysql_field_name--Gets the field name of the specified field in the result

Mysql_field_seek--Sets the pointer in the result set to the defined field offset

Mysql_field_table--Gets the name of the table that contains the specified field

Mysql_field_type--Gets the type of the specified field in the result set

Mysql_free_result--releasing the resulting memory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.