search
HomeDatabaseMysql TutorialMysql数据库导致CPU很高的问题解决_MySQL

    服务器环境 Liunx AS4 + PHP5 + Mysql5 + Apache 2
    实用TOP 命令查询系统性能的时候发现CPU经常到达100%
    开始以为是DDOS攻击……加装了防火墙(没起作用)
    又开始从liunx系统查找是不是系统问题,(也没起作用)
    偶尔从网络上发现一篇文章,有人也类似遇到了这样的问题,但并没指出具体解决方案,
    不过提醒了我,不是系统问题就是程序问题!
    这次我开始从新过滤PHP代码,偶尔发现很多兄弟写的代码只有“常”连接,竟然没有Close!
     我把所以的页面都加装了数据库关闭,发现CPU一直就保持在1%~10%之间(正常)
    所以提醒大家在写PHP程序的时候不要为了一点懒,导致系统溢出这样低级的错误!
    好了就写倒这里了,一个小问题花了我几乎一个下午搞这个!也算是教训!
    把一些mysql常用函数贴上,请牢记!其他类型数据库举一反三!
    mysql_affected_rows -- 取得前一次 MySQL 操作所影响的记录行数
    mysql_change_user -- 改变活动连接中登录的用户
    mysql_client_encoding -- 返回字符集的名称
    mysql_close -- 关闭 MySQL 连接
    mysql_connect -- 打开一个到 MySQL 服务器的连接
    mysql_create_db -- 新建一个 MySQL 数据库
    mysql_data_seek -- 移动内部结果的指针
    mysql_db_name -- 取得结果数据
    mysql_db_query -- 发送一条 MySQL 查询
    mysql_drop_db -- 丢弃(删除)一个 MySQL 数据库
    mysql_errno -- 返回上一个 MySQL 操作中的错误信息的数字编码
    mysql_error -- 返回上一个 MySQL 操作产生的文本错误信息
    mysql_escape_string -- 转义一个字符串用于 mysql_query
    mysql_fetch_array -- 从结果集中取得一行作为关联数组,或数字数组,或二者兼有
    mysql_fetch_assoc -- 从结果集中取得一行作为关联数组
    mysql_fetch_field -- 从结果集中取得列信息并作为对象返回
    mysql_fetch_lengths -- 取得结果集中每个输出的长度
    mysql_fetch_object -- 从结果集中取得一行作为对象
    mysql_fetch_row -- 从结果集中取得一行作为枚举数组
    mysql_field_flags -- 从结果中取得和指定字段关联的标志
    mysql_field_len -- 返回指定字段的长度
    mysql_field_name -- 取得结果中指定字段的字段名
    mysql_field_seek -- 将结果集中的指针设定为制定的字段偏移量
    mysql_field_table -- 取得指定字段所在的表名
    mysql_field_type -- 取得结果集中指定字段的类型
    mysql_free_result -- 释放结果内存
    mysql_get_client_info -- 取得 MySQL 客户端信息
    mysql_get_host_info -- 取得 MySQL 主机信息
    mysql_get_proto_info -- 取得 MySQL 协议信息
    mysql_get_server_info -- 取得 MySQL 服务器信息
    mysql_info -- 取得最近一条查询的信息
    mysql_insert_id -- 取得上一步 INSERT 操作产生的 ID
    mysql_list_dbs -- 列出 MySQL 服务器中所有的数据库
    mysql_list_fields -- 列出 MySQL 结果中的字段
    mysql_list_processes -- 列出 MySQL 进程
    mysql_list_tables -- 列出 MySQL 数据库中的表
    mysql_num_fields -- 取得结果集中字段的数目
    mysql_num_rows -- 取得结果集中行的数目
    mysql_pconnect -- 打开一个到 MySQL 服务器的持久连接
    mysql_ping -- Ping 一个服务器连接,如果没有连接则重新连接
    mysql_query -- 发送一条 MySQL 查询
    mysql_real_escape_string -- 转义 SQL 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集
    mysql_result -- 取得结果数据
    mysql_select_db -- 选择 MySQL 数据库
    mysql_stat -- 取得当前系统状态
    mysql_tablename -- 取得表名
    mysql_thread_id -- 返回当前线程的 ID
    mysql_unbuffered_query -- 向 MySQL 发送一条 SQL 查询,并不获取和缓存结果的行

Statement
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
MySQL String Types: Storage, Performance, and Best PracticesMySQL String Types: Storage, Performance, and Best PracticesMay 10, 2025 am 12:02 AM

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

Understanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreUnderstanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreMay 10, 2025 am 12:02 AM

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

What are the String Data Types in MySQL?What are the String Data Types in MySQL?May 10, 2025 am 12:01 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!