MySQL:查看全局变量和修改编码
mysql配置有很多变量,可以用show语句查看,如:
show variables like "datadir";
-- 输出:
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/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 | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
临时设置某个变量用set:
set global max_connections=2048; --设置最大连接数
mysql默认的编码是Latin1,也就是ISO-8859-1的别名,
若要永久修改其编码,修改配置文件/etc/my.cnf
,加入以下语句:
[mysqld]
character-set-server=utf8
修改数据库编码以后,以前建立的库还是原来的编码。