Mysql疑難雜症收集

 

Mysql疑難雜症收集

By Eagoo

    一、可疑問題:

        mysql>show processlist;

        | 20681949 | unauthenticated user | 10.10.4.193:52497 | NULL | Connect | | Reading from net | NULL | 

        | 20681948 | unauthenticated user | 10.10.4.193:52495 | NULL | Connect | | Reading from net | NULL | 

    發現有非常多的 unauthenticated user 嘗試做登入使用 mysql 的情況 ,當這種情況無限制發生時就會造成系統十分緩慢。

    查閱mysql官方網站得知,這屬於官方一個系統上的特殊設定,就把他當成mysql的一個bug算了。不管鏈接的的方式是經過 hosts 或是 IP 的模式,他都會對 DNS 做反查 mysqld 會嘗試去反查 IP -> DNS,由於反查解析過慢,就會無法應付過量的查詢。

    解決辦法:

        /usr/local/mysql/bin/mysqld_safe --skip-name-resolve --user=mysql &

        加 --skip-name-resolve 這麼一個參數就可以,關閉mysql的dns反查功能。

 

    二、Concat 亂碼問題:

 

    concat(str1,str2)

    當concat結果集出現亂碼時,大都是由於連接的字段類型不同導致,如concat中的字段參數一個是varchar類型,一個是int類型或doule類型,就會出現亂碼。

    解決方法:

    利用mysql的字符串轉換函數CONVERT將參數格式化爲char類型就可以了。

    舉例:

        concat('數量:',CONVERT(int1,char),CONVERT(int2,char),'金額:',CONVERT(double1,char),CONVERT(double2,char))

 

    三、UNION會出現Collection字符集不匹配的問題

    解決方法;Jdbc鏈接使用character  Encoding配置正確的字符集

    跟新jdbc驅動也是必須的,有時。

 

    四、偶爾因爲斷電導致mysql slave 出現複製錯誤“Could not parse relay log event entry”

    通常的解決辦法:

    Say a slave server runs out of disk space and the slave relay binlog is corrupt, 

    but the master binlogs are ok (as tested with mysqlbinlog). 

    Do I then do "show slave status /G" 

    Master_Log_File: mysql_master-bin.000164

    Read_Master_Log_Pos: 980240603

    Relay_Log_File: slave2-relay-bin.000001

    Relay_Log_Pos: 251111

    Relay_Master_Log_File: mysql_master-bin.000164

    Exec_Master_Log_Pos: 980240603

    and then

    stop slave;

    and then

    CHANGE MASTER TO <what should go here?> 

    ,MASTER_LOG_FILE = <Relay_Master_Log_File?> 

    ,MASTER_LOG_POS = <Exec_Master_Log_Pos?> 

    例如:

    CHANGE MASTER TO MASTER_LOG_FILE = 'mysql_master-bin.000164',MASTER_LOG_POS =980240603;

    and then

    start slave ;

    show slave status /G;

 

 

    五、MySQL允許用戶將一個值存儲爲臨時變量,以便後面語句使用。 

    變量值通過SET語句或者在SELECT語句中使用:=設置,例查看佣金大於平均值的全部SALES_REP: 

    ========================

        mysql> select @avg := AVG(commission) FROM sales_rep; 

        +-------------------------+ 

        | @avg := AVG(commission) | 

        +-------------------------+ 

        | 11.600000000 | 

        +-------------------------+ 

    ========================

        mysql> select first_name,surname from sales_rep where commission>@avg; 

        +------------+----------+ 

        | first_name | surname | 

        +------------+----------+ 

        | So1 | Rive | 

        | Charlene | Gordimer | 

        +------------+----------+ 

    ======================== 

    在第一個select 語句中我們:=定義了一個用戶變量@avg,在第二個SELECT中我們使用了該變量。

 

本文原創自無線技術運營空間: http://wireless.qzone.qq.com 及 http://blog.csdn.net/wireless_tech (專注無線技術運營——無線技術(操作系統/數據庫/WEB前端/負載均衡/系統容災/系統安全/短信接入/WAP接入/3G等)、無線業務運營、無線開放平臺、統計分析(用戶行爲分析/數據挖掘)、CP合作,聯繫我們:[email protected]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章