一个有关MYSQL的文章.E文的.MySQLs Query Cache_PHP教程
http://www.discuz.net/viewthread.php?tid=43137&sid=G4jizDNovember 18, 2003MySQLs Query CacheBy Ian GilfillanA typical scenarioBoss: Our new website is crawling! How can it be, we have four state-of-the-art web servers - whats the problem?You: Well, the web servers are fine - its the database server thats struggling.Boss: What? You told me this MySQL thing was fast, that we didnt need Oracle, and now you say it cant cope! How can this be?You: Well, the web servers are behaving so well that theyre pushing through lots of queries, and the database cant manage to process all of them at the same time. Its only one database, and lots of web servers...Boss: Its too late to buy Oracle now - what are we going to do!?Big Boss to Boss(in the bosss mind): This project has been a disaster from the beginning - now you want me to delay it while we install a new database, and spend a whole lot more! Do you think were made of money!? Im calling in someone who knows what theyre doing - youre history buddy.Colleague (about to take your job): Wait, I think I can solve the problem!So, what does your colleague know that you dont? How can he save the day and let the boss get all the credit? Our scenario is too imprecise to generalize, and there are many possible solutions. You can read about optimizing queries and indexes, optimizing by improving the hardware, and tweaking the MySQL variables, using the slow query log, and of course, there are other methods such as replication. However, MySQL 4 provides one feature that can prove very handy - a query cache. In a situation where the database has to repeatedly run the same queries on the same data set, returning the same results each time, MySQL can cache the result set, avoiding the overhead of running through the data over and over. Usually, you would want to implement some sort of caching on the web server, but there are times when this is not possible, and then it is the query cache you will look to for help.Setting up the query cacheTo make sure MySQL uses the query cache, there are a few variables you need to set in the configuration file (usually my.cnf or my.ini). First, is the query_cache_type. There are three possible settings: 0 (for off, do not use), 1 (for on, cache queries) and 2 (on demand, discussed more below). To ensure it is always on, place: query-cache-type = 1in the configuration file. If you started the server having only made this change, you would see the following cache variables set: mysql> SHOW VARIABLES LIKE %query_cache%;+-------------------+---------+| Variable_name | Value |+-------------------+---------+| have_query_cache | YES || query_cache_limit | 1048576 || query_cache_size | 0 || query_cache_type | ON |+-------------------+---------+4 rows in set (0.06 sec)Note that these are results from MySQL 4.0.x - youll see more in versions 4.1.x and beyond. The query_cache_type will be set to ON or OFF as appropriate. However, there is one more to set, and that is the query_cache_size. If set to 0 (the default), the cache will be disabled. This variable determines the memory, in bytes, used for the query cache. For our purposes, we will set it to 20 MB: query-cache-size = 20MThe amount is shown in bytes: mysql> SHOW VARIABLES LIKE %query_cache%;+-------------------+----------+| Variable_name | Value |+-------------------+----------+| have_query_cache | YES || query_cache_limit | 1048576 || query_cache_size | 20971520 || query_cache_type | ON |+-------------------+----------+4 rows in set (0.06 sec)The Query cache in action (almost)For this tutorial, I used a dump from Wikipedia, the open content encyclopedia (you can find the dumps here. I am using a fairly slow machine, with nothing else happening on it, to minimize interference in the results. Lets run the same query twice, and see how much improvement we see the second time: SELECT * FROM cur;...14144 rows in set (2.96 sec)Now we run the same query again: SELECT * FROM cur; 14144 rows in set (3.02 sec) Now we run the same query again: SELECT * FROM cur; 14144 rows in set (3.02 sec) What is happening? We would expect the second query to take noticeably less time. Lets examine some of the status variables to get a better picture. mysql> SHOW STATUS LIKE %qcache%;+-------------------------+----------+| Variable_name | Value |+-------------------------+----------+| Qcache_queries_in_cache | 0 || Qcache_inserts | 2 || Qcache_hits | 0 || Qcache_lowmem_prunes | 0 || Qcache_not_cached | 2 || Qcache_free_memory | 20962720 || Qcache_free_blocks | 1 || Qcache_total_blocks | 1 |+-------------------------+----------+8 rows in set (0.00 sec)The two queries we ran are both recorded (by Qcache_inserts), but neither of them have been cached. (You may get different results if other queries have been running.) The problem is that the result set is too big. I used the Wikipedia Esperanto dump (4MB compressed - the English dump is 135MB, and even though my English is better than my Esperanto, bandwidth is expensive in South Africa!), but it is immaterial, as even that is more than the query cache can handle by default. There are two limits in play here - the limit for each individual query is determined by the value of query_cache_limit, which is 1MB by default. Moreover, the limit of the cache in total is determined by query_cache_size, which we have seen already. The former limit applies here. If a result set is greater than 1M, it is not cached. The Query cache in action (really)Lets try a smaller query: SELECT cur_is_new FROM cur WHERE cur_user_text > Y...2336 rows in set (0.38 sec)Lets see if this one was cached:mysql> SHOW STATUS LIKE %qcache%;+-------------------------+----------+| Variable_name | Value |+-------------------------+----------+| Qcache_queries_in_cache | 1 || Qcache_inserts | 3 || Qcache_hits | 0 || Qcache_lowmem_prunes | 0 || Qcache_not_cached | 2 || Qcache_free_memory | 20947592 || Qcache_free_blocks | 1 || Qcache_total_blocks | 4 |+-------------------------+----------+8 rows in set (0.00 sec)There is now a query in the cache. If it took 0.38 seconds to run the first time, lets see if we notice an improvement the second time: SELECT cur_is_new FROM cur WHERE cur_user_text > Y...2336 rows in set (0.11 sec)Much better! And, looking at the status again: mysql> SHOW STATUS LIKE %qcache%;+-------------------------+----------+| Variable_name | Value |+-------------------------+----------+| Qcache_queries_in_cache | 1 || Qcache_inserts | 3 || Qcache_hits | 1 || Qcache_lowmem_prunes | 0 || Qcache_not_cached | 2 || Qcache_free_memory | 20947592 || Qcache_free_blocks | 1 || Qcache_total_blocks | 4 |+-------------------------+----------+8 rows in set (0.06 sec)The cache has been hit once. The status variables above should be fairly self-explanatory. Available memory for the cache has gone from 20962720 to 20947592 bytes. The most useful variable for future tuning is Qcache_lowmem_prunes. Each time a cached query is removed from the query cache, (because MySQL needs to make space for another), this value will be incremented. If it increases quickly, and you still have memory to spare, you can up the query_cache_size, while if it never increases, you can reduce the cache size. Lets run the query again, with a slight difference, as follows: SELECT cur_is_new from cur where cur_user_text > Y...2336 rows in set (0.33 sec)That took longer than we would have expected. Lets look at the status variables to see whats up: mysql> SHOW STATUS LIKE %qcache%;+-------------------------+----------+| Variable_name | Value |+-------------------------+----------+| Qcache_queries_in_cache | 2 || Qcache_inserts | 4 || Qcache_hits | 1 || Qcache_lowmem_prunes | 0 || Qcache_not_cached | 2 || Qcache_free_memory | 20932976 || Qcache_free_blocks | 1 || Qcache_total_blocks | 6 |+-------------------------+----------+The query has not made use of the cache - in fact, MySQL has inserted another query in the cache! The proble

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









MySQLデータベースでは、ユーザーとデータベースの関係は、アクセス許可と表によって定義されます。ユーザーには、データベースにアクセスするためのユーザー名とパスワードがあります。許可は助成金コマンドを通じて付与され、テーブルはCreate Tableコマンドによって作成されます。ユーザーとデータベースの関係を確立するには、データベースを作成し、ユーザーを作成してから許可を付与する必要があります。

データ統合の簡素化:AmazonrdsmysqlとRedshiftのゼロETL統合効率的なデータ統合は、データ駆動型組織の中心にあります。従来のETL(抽出、変換、負荷)プロセスは、特にデータベース(AmazonrdsmysQlなど)をデータウェアハウス(Redshiftなど)と統合する場合、複雑で時間がかかります。ただし、AWSは、この状況を完全に変えたゼロETL統合ソリューションを提供し、RDSMYSQLからRedshiftへのデータ移行のための簡略化されたほぼリアルタイムソリューションを提供します。この記事では、RDSMysQl Zero ETLのRedshiftとの統合に飛び込み、それがどのように機能するか、それがデータエンジニアと開発者にもたらす利点を説明します。

MySQLには、無料のコミュニティバージョンと有料エンタープライズバージョンがあります。コミュニティバージョンは無料で使用および変更できますが、サポートは制限されており、安定性要件が低く、技術的な能力が強いアプリケーションに適しています。 Enterprise Editionは、安定した信頼性の高い高性能データベースを必要とするアプリケーションに対する包括的な商業サポートを提供し、サポートの支払いを喜んでいます。バージョンを選択する際に考慮される要因には、アプリケーションの重要性、予算編成、技術スキルが含まれます。完璧なオプションはなく、最も適切なオプションのみであり、特定の状況に応じて慎重に選択する必要があります。

1.正しいインデックスを使用して、データの量を削減してデータ検索をスピードアップしました。テーブルの列を複数回検索する場合は、その列のインデックスを作成します。あなたまたはあなたのアプリが基準に従って複数の列からのデータが必要な場合、複合インデックス2を作成します2。選択した列のみを避けます。必要な列のすべてを選択すると、より多くのサーバーメモリを使用する場合にのみサーバーが遅くなり、たとえばテーブルにはcreated_atやupdated_atやupdated_atなどの列が含まれます。

MySQLのユーザー名とパスワードを入力するには:1。ユーザー名とパスワードを決定します。 2。データベースに接続します。 3.ユーザー名とパスワードを使用して、クエリとコマンドを実行します。

MySQLデータベースパフォーマンス最適化ガイドリソース集約型アプリケーションでは、MySQLデータベースが重要な役割を果たし、大規模なトランザクションの管理を担当しています。ただし、アプリケーションのスケールが拡大すると、データベースパフォーマンスのボトルネックが制約になることがよくあります。この記事では、一連の効果的なMySQLパフォーマンス最適化戦略を検討して、アプリケーションが高負荷の下で効率的で応答性の高いままであることを保証します。実際のケースを組み合わせて、インデックス作成、クエリ最適化、データベース設計、キャッシュなどの詳細な主要なテクノロジーを説明します。 1.データベースアーキテクチャの設計と最適化されたデータベースアーキテクチャは、MySQLパフォーマンスの最適化の基礎です。いくつかのコア原則は次のとおりです。適切なデータ型を選択し、ニーズを満たす最小のデータ型を選択すると、ストレージスペースを節約するだけでなく、データ処理速度を向上させることもできます。

データベース酸属性の詳細な説明酸属性は、データベーストランザクションの信頼性と一貫性を確保するための一連のルールです。データベースシステムがトランザクションを処理する方法を定義し、システムのクラッシュ、停電、または複数のユーザーの同時アクセスの場合でも、データの整合性と精度を確保します。酸属性の概要原子性:トランザクションは不可分な単位と見なされます。どの部分も失敗し、トランザクション全体がロールバックされ、データベースは変更を保持しません。たとえば、銀行の譲渡が1つのアカウントから控除されているが別のアカウントに増加しない場合、操作全体が取り消されます。 TRANSACTION; updateaccountssetbalance = balance-100wh

MySQLのコピーと貼り付けには、次の手順が含まれています。データを選択し、Ctrl C(Windows)またはCMD C(MAC)でコピーします。ターゲットの場所を右クリックして、貼り付けまたはCTRL V(Windows)またはCMD V(MAC)を使用します。コピーされたデータは、ターゲットの場所に挿入されるか、既存のデータを置き換えます(データが既にターゲットの場所に存在するかどうかに応じて)。
