設定mysql資料庫預設支援中文
阿新 • • 發佈:2020-12-12
1. yum安裝mysql資料庫
[root@localhost ~]# yum -y install mariadb mariadb-server
2.修改mysql資料庫的配置檔案
配置檔案的位置 /etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
設定伺服器端
在 [mysqld] 下新增
character-set-server=utf8
新建[client],新增
default-character-set=utf8
修改後如圖:
3.重啟MySQL服務
[root@localhost ~]# systemctl restart mariadb
4.進入mysql檢視
預設已支援中文
[root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 99 Server version: 5.5.68-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show variables like '%char%'; +--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec) MariaDB [(none)]>
5.建立庫和表測試
MariaDB [(none)]> create database wg; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> use wg; Database changed MariaDB [wg]> create table student(id int,name varchar(20)); Query OK, 0 rows affected (0.01 sec) MariaDB [wg]> insert into student values(1,'冬天'); Query OK, 1 row affected (0.00 sec) MariaDB [wg]> select * from student; +------+--------+ | id | name | +------+--------+ | 1 | 冬天 | +------+--------+ 1 row in set (0.00 sec)