MySQL Query Cache(緩存) Sql代碼 www.2cto.com # Example MySQL config file for medium systems. #通過mysql-5.1.37-win32的my-medium.ini編輯生成,應用與數據庫在一台機器上。 # This is for a system with little memory (32M - 64M) where MySQL plays # an important part, or systems up to 128M where MySQL is used together with # other programs (such as a web server) # # You can copy this file to # /etc/my.cnf to set global options, # mysql-data-dir/my.cnf to set server-specific options (in this # installation this directory is C:\mysql\data) or # ~/.my.cnf to set user-specific options. # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients # # 以下選項會被MySQL客戶端應用讀取. # # 注意只有MySQL附帶的客戶端應用程序保證可以讀取這段內容. # # 如果你想你自己的MySQL應用程序獲取這些值 # # 需要在MySQL客戶端庫初始化的時候指定這些選項 www.2cto.com [client] #password = your_password #mysql客戶端默認端口,對於應用來說沒有意義,安裝程序不對此參數進行修改。 port = 3316 socket = /tmp/mysql.sock # Here follows entries for some specific programs # MySQL 服務端 # The MySQL server [mysqld] #數據庫端口,默認設置為3316,安裝程序自動識別端口,在3316,3326,3336,3346中選擇可用端口 port = 3316 socket = /tmp/mysql.sock skip-locking #MyISAM 相關選項,由於使用存儲引擎INNODB,所以此段設置保留默認,不做修改。 # # 關鍵詞緩沖的大小, 一般用來緩沖MyISAM表的索引塊. # # 不要將其設置大於你可用內存的30%, # # 因為一部分內存同樣被OS用來緩沖行數據 # # 甚至在你並不使用MyISAM 表的情況下, 你也需要仍舊設置起 8-64M 內存由於它同樣會被內部臨時磁盤表使用. key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K # # 用來做MyISAM表全表掃描的緩沖大小. # # 當全表掃描需要時,在對應線程中分配. read_buffer_size = 256K # # 當在排序之後,從一個已經排序好的序列中讀取行時,行數據將從這個緩沖中讀取來防止磁盤尋道. # # 如果你增高此值,可以提高很多ORDER BY的性能. # # 當需要時由每個線程分配 read_rnd_buffer_size = 512K # # 此緩沖當MySQL需要在 REPAIR, OPTIMIZE, ALTER 以及 LOAD DATA INFILE 到一個空表中引起重建索引時被分配. # # 這在每個線程中被分配.所以在設置大值時需要小心. myisam_sort_buffer_size = 8M # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (via the "enable-named-pipe" option) will render mysqld useless! # #skip-networking # Replication Master Server (default) # binary logging is required for replication # # 打開二進制日志功能. # # 在復制(replication)配置中,作為MASTER主服務器必須打開此項 # # 如果你需要從你最後的備份中做基於時間點的恢復,你也同樣需要二進制日志. log-bin=mysql-bin # binary logging format - mixed recommended binlog_format=mixed # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted # # 唯一的服務辨識號,數值位於 1 到 2^32-1之間. # # 此值在master和slave上都需要設置. # # 如果 "master-host" 沒有被設置,則默認為1, 但是如果忽略此選項,MySQL不會作為master生效. server-id = 1 # Replication Slave (comment out master section to use this) # # To configure this host as a replication slave, you can choose between # two methods : # # 1) Use the CHANGE MASTER TO command (fully described in our manual) - # the syntax is: # # CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, # MASTER_USER=<user>, MASTER_PASSWORD=<password> ; # # where you replace <host>, <user>, <password> by quoted strings and # <port> by the master's port number (3306 by default). # # Example: # # CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, # MASTER_USER='joe', MASTER_PASSWORD='secret'; # # OR # # 2) Set the variables below. However, in case you choose this method, then # start replication for the first time (even unsuccessfully, for example # if you mistyped the password in master-password and the slave fails to # connect), the slave will create a master.info file, and any later # change in this file to the variables' values below will be ignored and # overridden by the content of the master.info file, unless you shutdown # the slave server, delete master.info and restart the slaver server. # For that reason, you may want to leave the lines below untouched # (commented) and instead use CHANGE MASTER TO (see above) # # required unique id between 2 and 2^32 - 1 # (and different from the master) # defaults to 2 if master-host is set # but will not function as a slave if omitted #server-id = 2 # # The replication master for this slave - required #master-host = <hostname> # # The username the slave will use for authentication when connecting # to the master - required #master-user = <username> # # The password the slave will authenticate with when connecting to # the master - required #master-password = <password> # # The port the master is listening on. # optional - defaults to 3306 #master-port = <port> # # binary logging - not required for slaves, but recommended #log-bin=mysql-bin # Point the following paths to different dedicated disks #tmpdir = /tmp/ #log-update = /path-to-dedicated-directory/hostname # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = C:\mysql\data/ # # InnoDB 將數據保存在一個或者多個數據文件中成為表空間. # # 如果你只有單個邏輯驅動保存你的數據,一個單個的自增文件就足夠好了. # # 其他情況下.每個設備一個文件一般都是個好的選擇. # # 你也可以配置InnoDB來使用裸盤分區 - 請參考手冊來獲取更多相關內容 innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = C:\mysql\data/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high # # InnoDB使用一個緩沖池來保存索引和原始數據, 不像 MyISAM. # # 這裡你設置越大,你在存取表裡面數據時所需要的磁盤I/O越少. # # 在一個獨立使用的數據庫服務器上,你可以設置這個變量到服務器物理內存大小的80% # # 不要設置過大,否則,由於物理內存的競爭可能導致操作系統的換頁顛簸. # # 注意在32位系統上你每個進程可能被限制在 2-3.5G 用戶層面內存限制, # # 所以不要設置的太高. innodb_buffer_pool_size = 64M # # 附加的內存池被InnoDB用來保存 metadata 信息 # # 如果InnoDB為此目的需要更多的內存,它會開始從OS這裡申請內存. # # 由於這個操作在大多數現代操作系統上已經足夠快, 你一般不需要修改此值. # # SHOW INNODB STATUS 命令會顯示當先使用的數量. innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size # # 在日志組中每個日志文件的大小. # # 你應該設置日志文件總合大小到你緩沖池大小的25%~100% # # 來避免在日志文件覆寫上不必要的緩沖池刷新行為. # # 不論如何, 請注意一個大的日志文件大小會增加恢復進程所需要的時間. innodb_log_file_size = 32M # # 用來緩沖日志數據的緩沖區的大小. # # 當此值快滿時, InnoDB將必須刷新數據到磁盤上. # # 由於基本上每秒都會刷新一次,所以沒有必要將此值設置的太大(甚至對於長事務而言) innodb_log_buffer_size = 8M # # 如果設置為1 ,InnoDB會在每次提交後刷新(fsync)事務日志到磁盤上, # # 這提供了完整的ACID行為. # # 如果你願意對事務安全折衷, 並且你正在運行一個小的食物, 你可以設置此值到0或者2來減少由事務日志引起的磁盤I/O # # 0代表日志只大約每秒寫入日志文件並且日志文件刷新到磁盤. # # 2代表日志寫入日志文件在每次提交後,但是日志文件只有大約每秒才會刷新到磁盤上. innodb_flush_log_at_trx_commit = 1 # # 在被回滾前,一個InnoDB的事務應該等待一個鎖被批准多久. # # InnoDB在其擁有的鎖表中自動檢測事務死鎖並且回滾事務. # # 如果你使用 LOCK TABLES 指令, 或者在同樣事務中使用除了InnoDB以外的其他事務安全的存儲引擎 www.2cto.com # # 那麼一個死鎖可能發生而InnoDB無法注意到. # # 這種情況下這個timeout值對於解決這種問題就非常有幫助. innodb_lock_wait_timeout = 50 #————————自定義設置—————————— # 設置mysql的安裝目錄 basedir=c:\Program Files\MySQL # 設置mysql數據庫的數據的存放目錄,必須是data,或者是\xxx-data datadir=c:\Program Files\MySQL\data # 設置mysql服務器的字符集,默認編碼 default-character-set=utf8 #還原數據庫的sql文件如果包含視圖與存儲結構,需要添加 #log-bin-trust-function-creators=1 #通過以下語句更改默認存儲引擎InnoDB default-storage-engine=INNODB #InnoDB存儲引擎獨享表空間 innodb_file_per_table=1 # # 我們在cache中保留多少線程用於重用 # # 當一個客戶端斷開連接後,如果cache中的線程還少於thread_cache_size, # # 則客戶端線程被放入cache中. # # 這可以在你需要大量新連接的時候極大的減少線程創建的開銷 # # (一般來說如果你有好的線程模型的話,這不會有明顯的性能提升.) www.2cto.com thread_cache_size = 8 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [WinMySQLAdmin] # 指定mysql服務啟動啟動的文件 Server=c:\Program Files\MySQL\bin\mysqld.exe 注冊MySQL服務的方法: 修改相應路徑,在CMD下運行 "D:\Program Files\mysql-5.5.14-win32\bin\mysqld.exe" --install MySQL --defaults-file="D:\Program Files\mysql-5.5.14-win32\my.ini"