熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> MySQL >> 正文

修改Linux下MySQL編碼

2022-06-13   來源: MySQL 

  默認登錄mysql之後show variables like %character% 出現

  mysql> show variables like %character%;

  +++

  | Variable_name            | Value                      |

  +++

  | character_set_client     | latin                       |

  | character_set_connection | latin                       |

  | character_set_database   | latin                       |

  | character_set_filesystem | binary                     |

  | character_set_results    | latin                       |

  | character_set_server     | latin                       |

  | character_set_system     | utf                       |

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

  +++

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

  使用find命令查找cnf文件記得不要去找f因為它不一定存在而應該找f

  [root@linuxserver classes] find / iname f print

  /usr/share/doc/mysqlserver/f

  /usr/share/doc/mysqlserver/f

  /usr/share/doc/mysqlserver/myf

  /usr/share/doc/mysqlserver/f

  /usr/share/doc/mysqlserver/f

  /usr/share/texmf/webc/f

  /usr/share/texmf/webc/f

  /usr/share/texmf/webc/f

  /usr/share/texmf/tex/jadetex/f

  /usr/share/ssl/f

  找到之後復制一個出來

  cp /usr/share/doc/mysqlserver/f /etc/f

   打開f修改編碼

  vi /etc/f

  在[client]下增加defaultcharacterset=utf

  在[mysqld]下增加defaultcharacterset=utf

  同時加上init_connect=SET NAMES utf (設定連接mysql數據庫時使用utf編碼以讓mysql數據庫為utf運行)

  重新啟動mysql執行:sudo /etc/initd/mysql stop 然後sudo /etc/initd/mysql start

  mysql> show variables like %character%;

  +++

  | Variable_name            | Value                      |

  +++

  | character_set_client     | utf                       |

  | character_set_connection | utf                       |

  | character_set_database   | utf                       |

  | character_set_filesystem | binary                     |

  | character_set_results    | utf                       |

  | character_set_server     | utf                       |

  | character_set_system     | utf                       |

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

  +++

  即使做了以上修改如果直接數據庫再創建表然後存入中文取出來的會是問號解決的辦法是

  創建數據庫的時候指明默認字符集為utf

  create database test default character set utf;


From:http://tw.wingwit.com/Article/program/MySQL/201311/29441.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.