本文目錄一覽:
mysql安裝配置教程是什麼?
安裝MySQL
步驟
1、雙擊下載的MySQL安裝文件,進入MySQL安裝界面,首先進入「License Agreement(用戶許可證協議)」窗口,選中「I accept the license terms(我接受系統協議)」複選框,單擊「Next(下一步)」按鈕即可。有的會直接進入「Choosing a Setup Type(安裝類型選擇)」窗口,根據右側的安裝類型描述文件選擇適合自己的安裝類型,這裡選擇默認的安裝類型,如圖所示。
2、根據所選擇的安裝類型安裝Windows系統框架(framework),單擊Execute按鈕,安裝程序會自動完成框架的安裝,如圖所示。
3、當彈出安裝程序窗口時,勾選「我同意許可條款和條件」複選框,然後單擊「安裝」按鈕,如圖所示。
4、彈出「設置成功」的界面,表示該框架已經安裝完成,單擊「關閉」按鈕即可。所有的框架安裝均可參考本操作,如圖所示。
5、安裝完成後會在【status】列表下顯示Complete(安裝完成)。所需框架均安裝成功後,點擊Next按鈕,如圖所示。
6、進入安裝確認窗口,點擊Execute按鈕,開始MySQL各個組件的安裝,如圖所示。
7、開始安裝 MySQL 文件,安裝完成後在【Status】列表下顯示 Complete,如圖所示。
配置MySQL
MySQL安裝完成之後,需要對服務器進行配置,具體配置步驟如下:步驟
1、在安裝的最後一步中,點擊Next按鈕進入服務器配置窗口,進行配置信息的確認,確認後點擊Next按鈕,如圖所示。
2、進入MySQL網絡類型配置窗口,採用默認設置,點擊Next按鈕,如圖所示。
3、進入MySQL服務器類型配置窗口,採用默認設置,點擊Next按鈕,如圖所示。
4、MySQL端口號默認3306,如果沒有特殊需求一般不建議修改。繼續點擊Next按鈕即可。
5、進入設置服務器的密碼窗口,重複輸入兩次登錄密碼(建議字母數字加符號),點擊Next按鈕,如圖所示。
6、進入服務器名稱窗口設置服務器名稱,這裡無特殊需要也不建議修改。繼續單擊Next按鈕,如圖所示。
7、打開確認設置服務器窗口,點擊Execute按鈕完成MySQL的各項配置,如圖所示。
8、最後打開Windows任務管理器對話框,可以看到MySQL服務進程mysqld.exe已經啟動了,如圖所示。至此,就完成了Windows操作系統下MySQL數據庫的安裝和配置。
mysql怎麼打開
MySQL的用法如下:
一、準備工作:
1、打開任務管理器,啟動MySQL服務(點擊開始即可)。
2、打開下載好的連接工具Navicat,選擇要連接的數據庫(MySQL),彈出MySQL-新建連接窗口,點擊測試連接,出現連接成功,點擊確定。
二、新建數據庫:
在連接好的MySQL連接上點擊右鍵,選擇新建數據庫,彈出新建數據庫窗口後,取數據庫名,輸入字符集為utf8,輸入排序規則為utf8_icelandic_ci,點擊確定,即可創建成功。
三、新建數據庫表:
在表上點擊右鍵,選擇新建表,添加字段,設置標識列(勾選自動遞增)。
四、導入數據庫表:
準備一張要導入MySQL數據庫的表:在表上點擊右鍵,選擇運行SQL文件,彈出運行SQL文件,選擇數據庫表的位置,找到你要導入的表,點擊開始完成導入,然後關閉即可。再次在表上點擊右鍵,選擇刷新,完成表的導入。
五、寫sql語句:
點擊新建查詢,然後選擇要連接的數據庫和表,即可盡情打代碼啦!!!
mysql耗內存嗎?應該怎麼處理?
mysql耗內存嗎?很多人都說MySQL佔用了很大的虛擬內存,那麼這個問題應該怎麼解決呢?下面是我收集整理的一些方法,現在分享給大家!
解決mysql耗內存的具體方法一:
在分析的過程中發現最耗內存的是MySQL,其中近1GB的內存被它吞了,而且不在任務管理器體現出來。這個數據庫軟件是EMS要用到了,所以必須要運行。這個軟件在安裝的時候會根據機器的實際內存自動進行配置,PC機物理內存越多,它默認佔有的內存就越多,難怪3GB的內存被它給吞了近1GB。
優化方法:
1. 退出EMS clientserver
2. 在CMD里運行:net stop mysql
3. 找到MySQL\MySQL Server的安裝目錄,裏面有個my.ini文件,參考附件的配置對參數query_cache_size tmp_table_size myisam_sort_buffer_size key_buffer_size innodb_buffer_pool_size進行修改,注意不要改動innodb_log_file_size,修改前備份my.ini
4. 在CMD里運行:net start mysql,如果提示成功,則說明修改的參數沒有什麼問題,如果失敗,重新調整一下上面的參數
5. 找到EMS 安裝目錄runGUI.bat runServer.bat腳本,找到-Xmx700m,改為-Xmx256m,注意修改前備份這兩個文件,感謝Liping Sun提供幫助
6. 重新運行EMS
前後對比,對於3GB的PC,發現可以節省近1GB的內存。對於2GB的PC,也可以節省600-800MB。優化後發現EMS啟動稍微慢一些,但是其它的軟件運行速度提高了很多,不在經常出現卡機現象了。如果在運行過程中發現EMS特別慢的話,自己也可以適當放大上面提到的一些參數。
my.ini
# MySQL Server Instance Configuration File
# ———————————————————————-
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ———————————————————————-
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# “–defaults-file”.
#
# To run run the server from the command line, execute this in a
# command line shell, e.g.
# mysqld –defaults-file=”C:\Program Files\MySQL\MySQL Server X.Y\my.ini”
#
# To install the server as a Windows service manually, execute this in a
# command line shell, e.g.
# mysqld –install MySQLXY –defaults-file=”C:\Program Files\MySQL\MySQL Server X.Y\my.ini”
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
#
# Guildlines for editing this file
# ———————————————————————-
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the “–help” option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
#
# CLIENT SECTION
# ———————————————————————-
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
# ———————————————————————-
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir=”D:/Program Files/MySQL/MySQL Server 5.1/”
#Path to the database root
datadir=”C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/”
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
# Set the SQL mode to strict
sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=1510
# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# “Qcache_lowmem_prunes” status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=16M
# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable “open-files-limit” in
# section [mysqld_safe]
table_cache=3020
# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=4M
# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client’s threads are put in the cache if there aren’t
# more than thread_cache_size threads from before. This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn’t give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=64
#*** MyISAM Specific options
# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G
# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=4M
# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you’re not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=16M
# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K
# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K
#*** INNODB Specific options ***
# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb
# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=9M
# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1
# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=5M
# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=32M
# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=88M
# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8
解決mysql耗內存的具體方法二:
更改後如下:
innodb_buffer_pool_size=576M -256M InnoDB引擎緩衝區佔了大頭,首要就是拿它開刀
query_cache_size=100M -16M 查詢緩存
tmp_table_size=102M -64M 臨時表大小
key_buffer_size=256m -32M
重啟mysql服務後,虛擬內存降到200以下.
另外mysql安裝目錄下有幾個文件:my-huge.ini 、my-large.ini、my-medium.ini…這幾個是根據內存大小作的建議配置,新手在設置的時候也可以參考一下。
2G內存的MYSQL數據庫服務器 my.ini優化 (my.ini)
2G內存,針對站少,優質型的設置,試驗特:
table_cache=1024 物理內存越大,設置就越大.默認為2402,調到512-1024最佳
innodb_additional_mem_pool_size=8M 默認為2M
innodb_flush_log_at_trx_commit=0 等到innodb_log_buffer_size列隊滿後再統一儲存,默認為1
innodb_log_buffer_size=4M 默認為1M
innodb_thread_concurrency=8 你的服務器CPU有幾個就設置為幾,默認為8
key_buffer_size=256M 默認為218 調到128最佳
tmp_table_size=64M 默認為16M 調到64-256最掛
read_buffer_size=4M 默認為64K
read_rnd_buffer_size=16M 默認為256K
sort_buffer_size=32M 默認為256K
max_connections=1024 默認為1210
試驗一:
table_cache=512或1024
innodb_additional_mem_pool_size=2M
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=1M
innodb_thread_concurrency=8 你的服務器CPU有幾個就設置為幾,默認為8
key_buffer_size=128M
tmp_table_size=128M
read_buffer_size=64K或128K
read_rnd_buffer_size=256K
sort_buffer_size=512K
max_connections=1024
試驗二:
table_cache=512或1024
innodb_additional_mem_pool_size=8M
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=4M
innodb_thread_concurrency=8
key_buffer_size=128M
tmp_table_size=128M
read_buffer_size=4M
read_rnd_buffer_size=16M
sort_buffer_size=32M
max_connections=1024
一般:
table_cache=512
innodb_additional_mem_pool_size=8M
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=4M
innodb_thread_concurrency=8
key_buffer_size=128M
tmp_table_size=128M
read_buffer_size=4M
read_rnd_buffer_size=16M
sort_buffer_size=32M
max_connections=1024
經過測試.沒有特殊情況,最好還是用默認的.
2G內存,針對站多,抗壓型的設置,最佳:
table_cache=1024 物理內存越大,設置就越大.默認為2402,調到512-1024最佳
innodb_additional_mem_pool_size=4M 默認為2M
innodb_flush_log_at_trx_commit=1
(設置為0就是等到innodb_log_buffer_size列隊滿後再統一儲存,默認為1)
innodb_log_buffer_size=2M 默認為1M
innodb_thread_concurrency=8 你的服務器CPU有幾個就設置為幾,建議用默認一般為8
key_buffer_size=256M 默認為218 調到128最佳
tmp_table_size=64M 默認為16M 調到64-256最掛
read_buffer_size=4M 默認為64K
read_rnd_buffer_size=16M 默認為256K
sort_buffer_size=32M 默認為256K
max_connections=1024 默認為1210
thread_cache_size=120 默認為60
query_cache_size=64M
優化mysql數據庫性能的十個參數
(1)、max_connections:
允許的同時客戶的數量。增加該值增加 mysqld 要求的文件描述符的數量。這個數字應該增加,否則,你將經常看到 too many connections 錯誤。 默認數值是100,我把它改為1024 。
(2)、record_buffer:
每個進行一個順序掃描的線程為其掃描的每張表分配這個大小的一個緩衝區。如果你做很多順序掃描,你可能想要增加該值。默認數值是131072(128k),我把它改為16773120 (16m)
(3)、key_buffer_size:
索引塊是緩衝的並且被所有的線程共享。key_buffer_size是用於索引塊的緩衝區大小,增加它可得到更好處理的索引(對所有讀和多重寫),到你能負擔得起那樣多。如果你使它太大,系統將開始換頁並且真的變慢了。默認數值是8388600(8m),我的mysql主機有2gb內存,所以我把它改為 402649088(400mb)。
4)、back_log:
要求 mysql 能有的連接數量。當主要mysql線程在一個很短時間內得到非常多的連接請求,這就起作用,然後主線程花些時間(儘管很短)檢查連接並且啟動一個新線程。
back_log 值指出在mysql暫時停止回答新請求之前的短時間內多少個請求可以被存在堆棧中。只有如果期望在一個短時間內有很多連接,你需要增加它,換句話說,這值對到來的tcp/ip連接的偵聽隊列的大小。你的操作系統在這個隊列大小上有它自己的限制。試圖設定back_log高於你的操作系統的限制將是無效的。
當你觀察你的主機進程列表,發現大量 264084 | unauthenticated user | xxx.xxx.xxx.xxx | null | connect | null | login | null 的待連接進程時,就要加大 back_log 的值了。默認數值是50,我把它改為500。
(5)、interactive_timeout:
服務器在關閉它前在一個交互連接上等待行動的秒數。一個交互的客戶被定義為對 mysql_real_connect()使用 client_interactive 選項的客戶。 默認數值是28800,我把它改為7200。
(6)、sort_buffer:
每個需要進行排序的線程分配該大小的一個緩衝區。增加這值加速order by或group by操作。默認數值是2097144(2m),我把它改為 16777208 (16m)。
(7)、table_cache:
為所有線程打開表的數量。增加該值能增加mysqld要求的文件描述符的數量。mysql對每個唯一打開的表需要2個文件描述符。默認數值是64,我把它改為512。
(8)、thread_cache_size:
可以復用的保存在中的線程的數量。如果有,新的線程從緩存中取得,當斷開連接的時候如果有空間,客戶的線置在緩存中。如果有很多新的線程,為了提高性能可以這個變量值。通過比較 connections 和 threads_created 狀態的變量,可以看到這個變量的作用。我把它設置為 80。
(9)mysql的搜索功能
用mysql進行搜索,目的是能不分大小寫,又能用中文進行搜索
只需起動mysqld時指定 –default-character-set=gb2312
(10)、wait_timeout:
服務器在關閉它之前在一個連接上等待行動的秒數。 默認數值是28800,我把它改為7200。
註:參數的調整可以通過修改 /etc/my.cnf 文件並重啟 mysql 實現。這是一個比較謹慎的工作,上面的結果也僅僅是我的一些看法,你可以根據你自己主機的硬件情況(特別是內存大小)進一步修改。
怎麼查看mysql文件描述符限制
何解決
第一步:設置OS參數(如果你有權限的話):
文件/etc/security/limits.conf新增如下行:
mysql soft nofile 65535
mysql hard nofile 65535
上面的配置,是OS限制各個用戶能夠打開的文件描述符限制(hard soft區別參看man ulimit),新增上面兩行,表示mysql用戶能夠打開65535個文件描述符(可以使用lsof -u mysql|wc -l查看當前打開了多少個文件描述符)。
第二步:修改MySQL參數:
在MySQL配置文件my.cnf中新增下面的行
mysql配置文件怎麼寫
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1 #表示是本機的序號為1,一般來講就是master的意思
skip-name-resolve
# 禁止MySQL對外部連接進行DNS解析,使用這一選項可以消除MySQL進行DNS解析的時間。但需要注意,如果開啟該選項,
# 則所有遠程主機連接授權都要使用IP地址方式,否則MySQL將無法正常處理連接請求
#skip-networking
back_log = 600
# MySQL能有的連接數量。當主要MySQL線程在一個很短時間內得到非常多的連接請求,這就起作用,
# 然後主線程花些時間(儘管很短)檢查連接並且啟動一個新線程。back_log值指出在MySQL暫時停止回答新請求之前的短時間內多少個請求可以被存在堆棧中。
# 如果期望在一個短時間內有很多連接,你需要增加它。也就是說,如果MySQL的連接數據達到max_connections時,新來的請求將會被存在堆棧中,
# 以等待某一連接釋放資源,該堆棧的數量即back_log,如果等待連接的數量超過back_log,將不被授予連接資源。
# 另外,這值(back_log)限於您的操作系統對到來的TCP/IP連接的偵聽隊列的大小。
# 你的操作系統在這個隊列大小上有它自己的限制(可以檢查你的OS文檔找出這個變量的最大值),試圖設定back_log高於你的操作系統的限制將是無效的。
max_connections = 1000
# MySQL的最大連接數,如果服務器的並發連接請求量比較大,建議調高此值,以增加並行連接數量,當然這建立在機器能支撐的情況下,因為如果連接數越多,介於MySQL會為每個連接提供連接緩衝區,就會開銷越多的內存,所以要適當調整該值,不能盲目提高設值。可以過’conn%’通配符查看當前狀態的連接數量,以定奪該值的大小。
max_connect_errors = 6000
# 對於同一主機,如果有超出該參數值個數的中斷錯誤連接,則該主機將被禁止連接。如需對該主機進行解禁,執行:FLUSH HOST。
open_files_limit = 65535
# MySQL打開的文件描述符限制,默認最小1024;當open_files_limit沒有被配置的時候,比較max_connections*5和ulimit -n的值,哪個大用哪個,
# 當open_file_limit被配置的時候,比較open_files_limit和max_connections*5的值,哪個大用哪個。
table_open_cache = 128
# MySQL每打開一個表,都會讀入一些數據到table_open_cache緩存中,當MySQL在這個緩存中找不到相應信息時,才會去磁盤上讀取。默認值64
# 假定系統有200個並發連接,則需將此參數設置為200*N(N為每個連接所需的文件描述符數目);
# 當把table_open_cache設置為很大時,如果系統處理不了那麼多文件描述符,那麼就會出現客戶端失效,連接不上
max_allowed_packet = 4M
# 接受的數據包大小;增加該變量的值十分安全,這是因為僅當需要時才會分配額外內存。例如,僅當你發出長查詢或MySQLd必須返回大的結果行時MySQLd才會分配更多內存。
# 該變量之所以取較小默認值是一種預防措施,以捕獲客戶端和服務器之間的錯誤信息包,並確保不會因偶然使用大的信息包而導致內存溢出。
binlog_cache_size = 1M
# 一個事務,在沒有提交的時候,產生的日誌,記錄到Cache中;等到事務提交需要提交的時候,則把日誌持久化到磁盤。默認binlog_cache_size大小32K
max_heap_table_size = 8M
# 定義了用戶可以創建的內存表(memory table)的大小。這個值用來計算內存表的最大行數值。這個變量支持動態改變
tmp_table_size = 16M
# MySQL的heap(堆積)表緩衝大小。所有聯合在一個DML指令內完成,並且大多數聯合甚至可以不用臨時表即可以完成。
# 大多數臨時表是基於內存的(HEAP)表。具有大的記錄長度的臨時表 (所有列的長度的和)或包含BLOB列的表存儲在硬盤上。
# 如果某個內部heap(堆積)表大小超過tmp_table_size,MySQL可以根據需要自動將內存中的heap表改為基於硬盤的MyISAM表。還可以通過設置tmp_table_size選項來增加臨時表的大小。也就是說,如果調高該值,MySQL同時將增加heap表的大小,可達到提高聯接查詢速度的效果
read_buffer_size = 2M
# MySQL讀入緩衝區大小。對錶進行順序掃描的請求將分配一個讀入緩衝區,MySQL會為它分配一段內存緩衝區。read_buffer_size變量控制這一緩衝區的大小。
# 如果對錶的順序掃描請求非常頻繁,並且你認為頻繁掃描進行得太慢,可以通過增加該變量值以及內存緩衝區大小提高其性能
read_rnd_buffer_size = 8M
# MySQL的隨機讀緩衝區大小。當按任意順序讀取行時(例如,按照排序順序),將分配一個隨機讀緩存區。進行排序查詢時,
# MySQL會首先掃描一遍該緩衝,以避免磁盤搜索,提高查詢速度,如果需要排序大量數據,可適當調高該值。但MySQL會為每個客戶連接發放該緩衝空間,所以應盡量適當設置該值,以避免內存開銷過大
sort_buffer_size = 8M
# MySQL執行排序使用的緩衝大小。如果想要增加ORDER BY的速度,首先看是否可以讓MySQL使用索引而不是額外的排序階段。
# 如果不能,可以嘗試增加sort_buffer_size變量的大小
join_buffer_size = 8M
# 聯合查詢操作所能使用的緩衝區大小,和sort_buffer_size一樣,該參數對應的分配內存也是每連接獨享
thread_cache_size = 8
# 這個值(默認8)表示可以重新利用保存在緩存中線程的數量,當斷開連接時如果緩存中還有空間,那麼客戶端的線程將被放到緩存中,
# 如果線程重新被請求,那麼請求將從緩存中讀取,如果緩存中是空的或者是新的請求,那麼這個線程將被重新創建,如果有很多新的線程,
# 增加這個值可以改善系統性能.通過比較Connections和Threads_created狀態的變量,可以看到這個變量的作用。(–表示要調整的值)
# 根據物理內存設置規則如下:
# 1G — 8
# 2G — 16
# 3G — 32
# 大於3G — 64
query_cache_size = 8M
#MySQL的查詢緩衝大小(從4.0.1開始,MySQL提供了查詢緩衝機制)使用查詢緩衝,MySQL將SELECT語句和查詢結果存放在緩衝區中,
# 今後對於同樣的SELECT語句(區分大小寫),將直接從緩衝區中讀取結果。根據MySQL用戶手冊,使用查詢緩衝最多可以達到238%的效率。
# 通過檢查狀態值’Qcache_%’,可以知道query_cache_size設置是否合理:如果Qcache_lowmem_prunes的值非常大,則表明經常出現緩衝不夠的情況,
# 如果Qcache_hits的值也非常大,則表明查詢緩衝使用非常頻繁,此時需要增加緩衝大小;如果Qcache_hits的值不大,則表明你的查詢重複率很低,
# 這種情況下使用查詢緩衝反而會影響效率,那麼可以考慮不用查詢緩衝。此外,在SELECT語句中加入SQL_NO_CACHE可以明確表示不使用查詢緩衝
query_cache_limit = 2M
#指定單個查詢能夠使用的緩衝區大小,默認1M
key_buffer_size = 4M
#指定用於索引的緩衝區大小,增加它可得到更好處理的索引(對所有讀和多重寫),到你能負擔得起那樣多。如果你使它太大,
# 系統將開始換頁並且真的變慢了。對於內存在4GB左右的服務器該參數可設置為384M或512M。通過檢查狀態值Key_read_requests和Key_reads,
# 可以知道key_buffer_size設置是否合理。比例key_reads/key_read_requests應該儘可能的低,
# 至少是1:100,1:1000更好(上述狀態值可以使用SHOW STATUS LIKE ‘key_read%’獲得)。注意:該參數值設置的過大反而會是服務器整體效率降低
ft_min_word_len = 4
# 分詞詞彙最小長度,默認4
transaction_isolation = REPEATABLE-READ
# MySQL支持4種事務隔離級別,他們分別是:
# READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE.
# 如沒有指定,MySQL默認採用的是REPEATABLE-READ,ORACLE默認的是READ-COMMITTED
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30 #超過30天的binlog刪除
log_error = /data/mysql/mysql-error.log #錯誤日誌路徑
slow_query_log = 1
long_query_time = 1 #慢查詢時間 超過1秒則為慢查詢
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1 #不區分大小寫
skip-external-locking #MySQL選項以避免外部鎖定。該選項默認開啟
default-storage-engine = InnoDB #默認存儲引擎
innodb_file_per_table = 1
# InnoDB為獨立表空間模式,每個數據庫的每個表都會生成一個數據空間
# 獨立表空間優點:
# 1.每個表都有自已獨立的表空間。
# 2.每個表的數據和索引都會存在自已的表空間中。
# 3.可以實現單表在不同的數據庫中移動。
# 4.空間可以回收(除drop table操作處,表空不能自已回收)
# 缺點:
# 單表增加過大,如超過100G
# 結論:
# 共享表空間在Insert操作上少有優勢。其它都沒獨立表空間表現好。當啟用獨立表空間時,請合理調整:innodb_open_files
innodb_open_files = 500
# 限制Innodb能打開的表的數據,如果庫里的表特別多的情況,請增加這個。這個值默認是300
innodb_buffer_pool_size = 64M
# InnoDB使用一個緩衝池來保存索引和原始數據, 不像MyISAM.
# 這裡你設置越大,你在存取表裏面數據時所需要的磁盤I/O越少.
# 在一個獨立使用的數據庫服務器上,你可以設置這個變量到服務器物理內存大小的80%
# 不要設置過大,否則,由於物理內存的競爭可能導致操作系統的換頁顛簸.
# 注意在32位系統上你每個進程可能被限制在 2-3.5G 用戶層面內存限制,
# 所以不要設置的太高.
還沒完,字數受限制,這裡有詳細的參數說明:
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/200485.html