IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁(yè)數(shù)據(jù)庫(kù)MYSQL → 修改Linux下MySQL編碼

修改Linux下MySQL編碼

時(shí)間:2015-06-28 00:00:00 來(lái)源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評(píng)論(1)

  默認(rèn)登錄mysql之后show variables like '%character%', 出現(xiàn)

  mysql> show variables like '%character%';

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

  | Variable_name????? | Value??? |

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

  | character_set_client???? | latin1???? |

  | character_set_connection | latin1???? |

  | character_set_database?? | latin1???? |

  | character_set_filesystem | binary?? |

  | character_set_results??? | latin1???? |

  | character_set_server???? | latin1???? |

  | character_set_system???? | utf8???? |

  | character_sets_dir | /usr/share/mysql/charsets/ |

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

  1. 找到mysql的配置文件,拷貝到etc目錄下,第一步很重要

  使用find命令查找cnf文件。記得不要去找my.cnf因?yàn)樗灰欢ù嬖?,而?yīng)該找*.cnf。

  [root@linuxserver classes] find / -iname *.cnf -print

  /usr/share/doc/mysql-server-4.1.12/my-medium.cnf

  /usr/share/doc/mysql-server-4.1.12/my-huge.cnf

  /usr/share/doc/mysql-server-4.1.12/my-innodb-heavy-4G.cnf

  /usr/share/doc/mysql-server-4.1.12/my-large.cnf

  /usr/share/doc/mysql-server-4.1.12/my-small.cnf

  /usr/share/texmf/web2c/mktex.cnf

  /usr/share/texmf/web2c/texmf.cnf

  /usr/share/texmf/web2c/fmtutil.cnf

  /usr/share/texmf/tex/jadetex/jadefmtutil.cnf

  /usr/share/ssl/openssl.cnf

  找到之后,復(fù)制一個(gè)出來(lái)

  cp /usr/share/doc/mysql-server-4.1.12/my-large.cnf /etc/my.cnf

  2. 打開(kāi)my.cnf修改編碼

  vi /etc/my.cnf

  在[client]下增加default-character-set=utf8

  在[mysqld]下增加default-character-set=utf8

  同時(shí)加上init_connect='SET NAMES utf8' (設(shè)定連接mysql數(shù)據(jù)庫(kù)時(shí)使用utf8編碼,以讓mysql數(shù)據(jù)庫(kù)為utf8運(yùn)行)

  重新啟動(dòng)mysql,執(zhí)行:sudo /etc/init.d/mysql stop 然后sudo /etc/init.d/mysql start

  mysql> show variables like '%character%';

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

  | Variable_name????? | Value??? |

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

  | character_set_client???? | utf8???? |

  | character_set_connection | utf8???? |

  | character_set_database?? | utf8???? |

  | character_set_filesystem | binary?? |

  | character_set_results??? | utf8???? |

  | character_set_server???? | utf8???? |

  | character_set_system???? | utf8???? |

  | character_sets_dir | /usr/share/mysql/charsets/ |

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

  即使做了以上修改如果直接數(shù)據(jù)庫(kù)再創(chuàng)建表,然后存入中文,取出來(lái)的會(huì)是問(wèn)號(hào)。解決的辦法是:

  創(chuàng)建數(shù)據(jù)庫(kù)的時(shí)候指明默認(rèn)字符集為utf8,如:

  create database test default character set utf8;

關(guān)鍵詞標(biāo)簽:Linux,MySQL編碼

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門文章 Xbox Game Pass Xbox Game Pass 10款MySQL數(shù)據(jù)庫(kù)客戶端圖形界面管理工具推薦 10款MySQL數(shù)據(jù)庫(kù)客戶端圖形界面管理工具推薦 MySQL常用維護(hù)管理工具 MySQL常用維護(hù)管理工具 MySQL數(shù)據(jù)庫(kù)啟動(dòng)失敗1067進(jìn)程意外終止的解決辦法總結(jié) MySQL數(shù)據(jù)庫(kù)啟動(dòng)失敗1067進(jìn)程意外終止的解決辦法總結(jié)

相關(guān)下載

    人氣排行 10款MySQL數(shù)據(jù)庫(kù)客戶端圖形界面管理工具推薦 MySQL數(shù)據(jù)庫(kù)啟動(dòng)失敗1067進(jìn)程意外終止的解決辦法總結(jié) Mysql 1045錯(cuò)誤解決辦法 MySQL服務(wù)器進(jìn)程CPU占用100%解決辦法 MySQL導(dǎo)出導(dǎo)入命令的用例 MySQL連接字符串的實(shí)際操作步驟匯總 MySQL無(wú)法啟動(dòng)、無(wú)法停止各種解決方法總結(jié) 三種常用的MySQL建表語(yǔ)句