標籤:mysql概述 my.conf實質
書讀百遍,其義自現。大家都知道,但是現在的社會真的很浮躁,又有多少人可以靜下來看看書呢?!!只要一有問題就是百度,Google...實際上,書上寫的很清楚,所有的解決方案都在書中,對於一個產品的瞭解,又有誰比編譯出他的人更清楚呢!
寫給自己,僅以自省!
MySQL官方手冊5.1
mysqld是MySQL伺服器
mysqld_safe、mysql.server是伺服器啟動指令碼
mysql_install_db初始化資料目錄和初始資料庫
mysql是一個命令列客戶程式,用於互動式或以批處理模式執行SQL語句。
mysqladmin是用於管理功能的客戶程式。
mysqldump負責Database Backup。
echo ‘export PATH=/application/mysql/sbin:$PATH‘ >/etc/profile
shell> mysql -u root -p -e "show databases;"
shell> mysql -u root -p -e "SELECT User,Host FROM mysql.User;"
/etc/my.cnf==>全域選項,就是啟動選項
任何可以在運行MySQL程式時在命令列給出的長選項也可以在選項檔案中給出。
在選項檔案中指定選項的文法類似於命令列文法,例外的是要忽略掉兩個破折號。
如果你有一個原始碼分發,可以從support-file目錄中找到名為my-xxxx.cnf的樣本選項檔案。
my-small.cnf預設配置:
[[email protected] support-files]# cat my-small.cnf# Example MySQL config file for small systems.## This is for a system with little memory (<= 64M) where MySQL is only used# from time to time and it‘s important that the mysqld daemon# doesn‘t use much resources.## MySQL programs look for option files in a set of# locations which depend on the deployment platform.# You can copy this option file to one of those# locations. For information about these locations, see:# http://dev.mysql.com/doc/mysql/en/option-files.html## 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[client]#password = your_passwordport = 3306socket = /application/mysql5.1.72/tmp/mysql.sock# Here follows entries for some specific programs# The MySQL server[mysqld]port = 3306socket = /application/mysql5.1.72/tmp/mysql.sockskip-lockingkey_buffer_size = 16Kmax_allowed_packet = 1Mtable_open_cache = 4sort_buffer_size = 64Kread_buffer_size = 256Kread_rnd_buffer_size = 256Knet_buffer_length = 2Kthread_stack = 128K# 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# (using the "enable-named-pipe" option) will render mysqld useless!# #skip-networkingserver-id = 1# Uncomment the following if you want to log updates#log-bin=mysql-bin# binary logging format - mixed recommended#binlog_format=mixed# Uncomment the following if you are using InnoDB tables#innodb_data_home_dir = /application/mysql5.1.72/data#innodb_data_file_path = ibdata1:10M:autoextend#innodb_log_group_home_dir = /application/mysql5.1.72/data# You can set .._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too high#innodb_buffer_pool_size = 16M#innodb_additional_mem_pool_size = 2M# Set .._log_file_size to 25 % of buffer pool size#innodb_log_file_size = 5M#innodb_log_buffer_size = 8M#innodb_flush_log_at_trx_commit = 1#innodb_lock_wait_timeout = 50[mysqldump]quickmax_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 = 8Msort_buffer_size = 8M[mysqlhotcopy]interactive-timeout
修改選項:
shell> mysql --max_allowed_packet=16M 允許通訊的最大長度
[mysql]
max_allowed_packet=16M
優先順序:
MySQL程式首先檢查環境變數-->選項檔案-->命令列來確定給出了哪些選項。
如果多次指定一個選項,最後出現的選項佔先。這說明環境變數具有最低的優先順序,命令列選項具有最高優先順序。
| 命令 |
模組 |
| mysqld |
從[mysqld]和[server]組讀取選項 |
| mysqld_safe |
從[mysqld]、[server]、[mysqld_safe]和[safe_mysqld]組讀取選項 |
| mysql.server |
從 [mysqld]和[mysql.server]組讀取選項。 |
--mysqld_safe
伺服器啟動指令碼。如果mysqld-max存在,mysqld_safe試圖啟動它,否則啟動mysqld。
mysqld_safe從選項檔案的[mysqld]、[server]和[mysqld_safe]部分讀取所有選項。
一般情況,你不應編輯mysqld_safe指令碼。相反,應使用命令列選項或my.cnf選項檔案的[mysqld_safe]部分的
選項來配置mysqld_safe。一般不需要編輯mysqld_safe來正確啟動伺服器。但是,如果你編輯,
將來升級MySQL後會覆蓋你修改的mysqld_safe版本,因此你應對你修改的版本進行備份以便將來重裝。
--mysql.server
伺服器啟動指令碼。該指令碼用於使用包含為特定層級的運行啟動服務的指令碼的運行目錄的系統。它調用mysqld_safe來啟動MySQL伺服器。
mysql.server位於MySQL源碼樹MySQL安裝目錄下的support-files目錄中。
如果你使用Linux 伺服器RPM軟體包(MySQL-server-VERSION.rpm),mysql.server指令碼將安裝到/etc/init.d目錄下,名為mysqld。
mysql.server從 [mysql.server]和選項檔案的[mysqld]部分讀取選項。
--mysql_install_db
該指令碼用預設許可權建立MySQL授權表。通常只是在系統上首次安裝MySQL時執行一次。
--線上臨時修改
+------------------+-------+| Variable_name | Value |+------------------+-------+| sort_buffer_size | 65536 |+------------------+-------+1 row in set (0.00 sec)mysql> SET GLOBAL sort_buffer_size = 10 * 1024 * 1024;mysql> \qBye...mysql> show variables like ‘sort_%‘;+------------------+----------+| Variable_name | Value |+------------------+----------+| sort_buffer_size | 10485760 |+------------------+----------+1 row in set (0.00 sec)
--可寫入my.conf內
[mysqld]sort_buffer_size = 10 * 1024 * 1024
mysql> show variables like ‘binlog_%‘;+-----------------------------------------+-----------+| Variable_name | Value |+-----------------------------------------+-----------+| binlog_cache_size | 32768 || binlog_direct_non_transactional_updates | OFF || binlog_format | STATEMENT || binlog_stmt_cache_size | 32768 |+-----------------------------------------+-----------+4 rows in set (0.00 sec)
補充:binlog_cache_size
在事務過程中容納二進位日誌SQL語句的緩衝大小。二進位日誌緩衝是伺服器支援事務儲存引擎並且伺服器啟用了二進位日誌(--log-bin選項)的前提下為每個用戶端分配的記憶體。如果你經常使用大的,多語句事務,你可以增加該值以獲得更有的效能。Binlog_cache_use和Binlog_cache_disk_use狀態變數可以用來調整該變數的大小。
本文出自 “挨刀客” 部落格,請務必保留此出處http://chboy.blog.51cto.com/9959876/1707410
MySQL必須知道的常識