mysql常見問題

season0891發表於2013-07-17
一:
出現這個問題,可能是mysql.sock不存在,或者找不到,或者檔案損害需要重新建立連線
1.檢視mysql.sock地址是否是正確地址
我通過vim /etc/my.cnf,修改了[mysqld]選項下面的socket的值
socket=/usr/local/mysql/var/mysql.sock   # 看看是否是mysql.sock的準確地址
或可以通過find / -name mysql.sock來檢視mysql.sock檔案的位置!
2 為/tmp/mysql.sock 建立連線
ln -s /usr/local/mysql/varmysql.sock /tmp/mysql.sock
3.怎樣保護“/tmp/mysql.sock   ”不被刪除
如果你有這個問題,事實上任何人可以刪除MySQL通訊套接字“/tmp/mysql.sock”,在Unix的大多數版本上,你能通過為其設定sticky(t)位來保護你的“/tmp”檔案系統。作為root登入並且做下列事情:
shell>   chmod   +t   /tmp
這將保護你的“/tmp”檔案系統使得檔案僅能由他們的所有者或超級使用者(root)刪除。
你能執行ls   -ld   /tmp檢查sticky位是否被設定,如果最後一位許可位是t,該位被設定了

二:mysql out of memory 
現象:mysql執行一段時間後,對外提供服務不正常! 準備先關閉mysql ,然後再重啟mysql服務
mysqladmin關閉mysqld服務時有如附件的提示:
mysql常見問題
解決方法:新增實體記憶體或修改my.cnf配置檔案!

三:修改某個db的預設編碼格式和顯示db支援的編碼格式
見附件:
mysql常見問題
4:朋友電話告知幫忙處理一個web連線不上db的問題!
檢視web程式的lib目錄下有mysql驅動jar包,版本也匹配!檢視mysql服務是否正常?正常,檢視防火牆上是否開放了3306埠? 開放了!但使用者用一個最簡單test.jsp(僅僅是測試資料庫連線的最簡單程式) ,但一直提示資料庫連線失敗,很是奇怪,原來是/etc/my.cnf中新增了--skip-network的緣故!註釋掉該行就可以了!
5: [ERROR] /usr/local/mysql/bin/mysqld: Sort aborted: Server shutdown in progress

There are two main reasons for this error message to show:

 

1) The MySQL query you are trying to execute takes too long and the MySQL server times out.

The solution for this issue is to optimize your database for the queries which fail.

 

2) You have a crashed table in your database.

The solution in this case is to repair and optimize your database.

 

If a particular table crashes often and repairing/optimizing it does not help,  this most probably means that the table's structure is not working properly with our MySQL server setup. In such cases the easiest way to fix a crashed MyISAM table for good is to change its database engine from MyISAM to InnoDB


6:mysqldump中--default-character-set引數理解:

7:太多的sleep程式
mysql -uroot -p***後登陸資料庫,show proceelist;發現有太多的sleep程式,見附件!

原因:my.cnf中的wait_timeout和interactive_timeout 設定的太大!
my.cnf中的相關設定如下:

wait_timeout            = 64800

interactive_timeout     = 64800

將其修改為:

wait_timeout            = 100

interactive_timeout     = 100
問題即可正常!
8:有一段時間測試兩個資料庫間同步,#我們的環境比較特殊不適合用mysql master/slave,有幾天測試使用rsync同步資料庫下的表,發現使用rsync同步後,表經常損壞!
首先要修復表,修復的方法:
mysqlcheck  -uroot –p***  --repair --extended  mydb
9:有時候為了確保資料一致性,需要重新整理mysql 快取
方法見附件:

10:有時候也可以優化資料庫:
mysqlcheck -u root -p**** --auto-repair --optimize --all-databases ##自動修復優化所有資料庫
11:修改使得root遠端登陸
:預設情況下,不允許root遠端登陸,進行下面修改後就可以使得root遠端登陸



12: shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

解決方法:

該錯誤表示 getcwd 命令無法定位到當前工作目錄。一般來說是因為你 cd 到了某個目錄之後 rm 了這個目錄,這時去執行某些 service 指令碼的時候就會報 getcwd 錯誤。只需要 cd 到任何一個實際存在的目錄下在執行命令即可。

13:配置master/slave時遇到兩個問題

13.1:

在slave上執行show master status;居然有顯示,

原因:我在slave上也開啟了log-bin檔案!

解決方法:將該行註釋掉,然後show master status就不會有結果顯示了!

13.2:在配置master/slave時,

使用了grant all on test.* to ‘slaveuser’@’%’ identified by ‘slaveuser’;  ##應該使用grant all on *.* to ‘slaveuser’@’%’ identified by ‘slaveuser’; 當然all的許可權太大了,可以適當的調小!

導致了就算slaveuser的密碼正確也會提示密碼錯誤!

14:為了安裝mysql5.5.X 編譯cmake,結果出錯,見附件


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-766447/,如需轉載,請註明出處,否則將追究法律責任。