Solve high CPU problems caused by Mysql database

Source: Internet
Author: User
Tags mysql functions mysql host

Server Environment Liunx AS4 + PHP5 + Mysql5 + Apache 2
When the TOP command is used to query the system performance, it is found that the CPU often reaches 100%.
I thought it was a DDOS attack ...... Firewall installed (ineffective)
Again, I started to find out if it was a system problem from the liunx system (and it didn't work)
I occasionally found an article on the Internet, and someone encountered such a problem, but did not point out the specific solution,
But I was reminded that either a system problem or a program problem!
This time, I began to filter PHP code again. Occasionally, I found that many of my brother's code is only a "regular" connection, and I didn't Close it!
I installed a database to close all the pages, and found that the CPU has been maintained at 1% ~ Between 10% (normal)
This reminds everyone not to be a bit lazy when writing PHP programs, resulting in system overflow such a low-level error!
Let's write it down here. I spent almost one afternoon on a small problem! It's also a lesson!
Remember to paste some common mysql functions! Other types of databases are similar!
Mysql_affected_rows -- gets the number of records affected by the previous MySQL operation
Mysql_change_user -- change the user logged on to the active connection
Mysql_client_encoding -- returns the name of the character set.
Mysql_close -- close the MySQL connection
Mysql_connect -- open a connection to the MySQL server
Mysql_create_db -- create a MySQL database
Mysql_data_seek -- move the internal result pointer
Mysql_db_name -- get result data
Mysql_db_query -- send a MySQL Query
Mysql_drop_db -- discard (delete) a MySQL database
Mysql_errno -- returns the numeric encoding of the error message in the previous MySQL operation
Mysql_error -- returns the text error message generated by the previous MySQL operation.
Mysql_escape_string -- escape a string for mysql_query
Mysql_fetch_array -- get a row from the result set as an associated array, or a number array, or both
Mysql_fetch_assoc -- get a row from the result set as the associated array
Mysql_fetch_field -- obtains column information from the result set and returns it as an object
Mysql_fetch_lengths -- get the length of each output in the result set
Mysql_fetch_object -- get a row from the result set as an object
Mysql_fetch_row -- obtains a row from the result set as an enumerated Array
Mysql_field_flags -- obtains the flag associated with the specified field from the result
Mysql_field_len -- returns the length of the specified field
Mysql_field_name -- obtains the field name of the specified field in the result.
Mysql_field_seek -- set the pointer in the result set to the specified field offset.
Mysql_field_table -- get the name of the table where the specified field is located
Mysql_field_type -- specify the field type in the result set
Mysql_free_result -- release result memory
Mysql_get_client_info -- Obtain MySQL client information
Mysql_get_host_info -- Obtain MySQL host information
Mysql_get_proto_info -- Obtain MySQL protocol information
Mysql_get_server_info -- Obtain MySQL Server Information
Mysql_info -- get the information of the last Query
Mysql_insert_id -- get the ID generated by the previous INSERT operation
Mysql_list_dbs -- list all databases on the MySQL server
Mysql_list_fields -- list fields in MySQL results
Mysql_list_processes -- list MySQL Processes
Mysql_list_tables -- list tables in the MySQL database
Mysql_num_fields -- obtain the number of fields in the result set.
Mysql_num_rows -- get the number of rows in the result set
Mysql_pconnect -- open a persistent connection to the MySQL server
Mysql_ping -- Ping a server connection. If there is no connection, reconnect.
Mysql_query -- send a MySQL Query
Mysql_real_escape_string -- escape special characters in strings used in SQL statements and take into account the connected Current Character Set
Mysql_result -- get result data
Mysql_select_db -- select MySQL database
Mysql_stat -- get the current system status
Mysql_tablename -- get the table name
Mysql_thread_id -- returns the ID of the current thread
Mysql_unbuffered_query -- a row that sends an SQL query to MySQL and does not obtain or cache the result.

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.