MySQL常用知识
-
查看数据库编码集
//查看编码集
show variables like “%char%”;
//查看端口
show global variables like ‘port’;//重启MySQL
systemctl restart mysqld
mysql> 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 | latin1 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set, 1 warning (0.00 sec)
character_set_client:客户端请求数据的字符集
character_set_connection:客户机与服务器连接的字符集
character_set_database:默认数据库的字符集;如果没有默认数据库,就会使用 character_set_server指定的字符集(建议不要随意更改)
character_set_filesystem:把 character_set_client转换character_set_filesystem (默认为binary, 不做任何转换)
character_set_results:返回给客户端的字符集
character_set_server:数据库服务器的默认字符集
character_set_system:系统字符集,默认utf8。(用于数据库的表、列和存储在目录表中函数的名字)
character_sets_dir:mysql字符集文件的保存路径
修改方法:my.cnf配置文件
//修改配置文件
vim /etc/my.cnf
···
port=2306 //修改端口(这个是新添加的原本没有)
//修改默认编码为utf-8 (这也是新添加的原本没有)
character_set_server=utf8
init_connect='SET NAMES utf8'
···
临时方法:重启会失效
set character_set_client = ‘utf8’;
set character_set_connection = ‘utf8’;
set character_set_results = ‘utf8’;