怎么在创建mysql数据库的时候指定编码?
default-character-set=utf82单独设置某个数据库:
alterdatabasetestdbcharactersetutf8;
查看mysql支持的编码:
showcharacterset;也可以使用如下方法查看编码:
showstatusmysql-urootuseyourdatabasestatus----------------------------------servercharacterset:utf8dbcharacterset:utf8clientcharacterset:utf8conn.characterset:utf8tcpport:3306uptime:53sec----------------------------------如果client为utf8,改为:setcharset'gbk';查看数据库编码:showcreatedatabaseyour_db_name
mysql如何修改默认字符集编码?
1、更改服务器的编码方式,在终端输入以下命令:mysqld--character-set-server=gbk--collation-server=gbk_chinese_ci;
2、更改某个数据库的编码方式mysql-uroot-p alterdatabasecharactersetgbkcollategbk_chinese_ci;
3、在创建数据库时指定编码:mysql-uroot-p createdatabasedb_namecharactersetgbkcollategbk_chinese_ci;
4、更改某个表的编码方式mysql-uroot-pdb_namealtertabletable_nameconvertto charachtersetgbkcollategbk_chinese_ci;
图片来源:网络
5、在创建表时指定编码方式mysql-uroot-pdb_namecreatetabletable_name(....)charactersetgbkcollategbk_chinese_ci;
6、更改某行的编码方式mysql-uroot-pdb_namealtertabletable_namemodifycolumn_namevarchar(20)charactersetgbkcollategbk_chinese_ci;
7、在创建列时指定编码方式:</pre><prename="code">mysql-uroot-pdb_namecreatetabletable_name(...,col1varchar(20)charactersetgbkcollategbk_chinese_ci,...)charactersetutf8collateutf8_general_ci;
MYSQL如何设置数据库编码?
(1)关闭mysql服务
[plain] view plaincopy
service mysql stop
(2)修改 /etc/mysql/my.cnf (默认的安装路径)
[plain] view plaincopy
vim /etc/mysql/my.cnf
打开my.cnf后,在文件内的[mysqld]下增加如下两行设置:
[plain] view plaincopy
character_set_server=utf8
init_connect='SET NAMES utf8'
保存退出。
(3) 重新启动mysql服务
[plain] view plaincopy
service mysql start
至此,完成修改默认编码