1. 程式人生 > 其它 >關於字串匹配查詢的總結(43天)

關於字串匹配查詢的總結(43天)

docker版mysql字符集設定

1.生成mysql容器執行例項,把資料,配置,日誌掛載在主機的資料夾下

  docker run -d -p 3306:3306 --name mysql5.7 --privileged=true -v /muxiaomian/mysql/log:/var/log/mysql -v /muxiaomian/mysql/data:/var/lib/mysql -v /muxiaomian/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456test mysql:5.7

  進入容器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/ |
  +--------------------------+----------------------------+

  在5.7中,預設是拉丁,插入中文會有問題

2.在 /muxiaomian/mysql/conf下編寫my.cnf檔案

  [client]
  default_character_set=utf8
  [mysqld]
  character_set_server=utf8_general_ci
  collation_server=utf8

3.重啟容器

  docker restart mysql5.7

  檢視字符集

  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/ |
  +--------------------------+----------------------------+

4.測試插入中文 

  mysql> select * from user;
  +------+-----------+
  | id | name |
  +------+-----------+
  | 1 | lucy |
  | 2 | 使用者名稱 |
  +------+-----------+