1、创建数据库的时候:
CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
2、建表的时候
CREATE TABLE `database_user` (
`ID` varchar(40) NOT NULL default '',
`UserID` varchar(40) NOT NULL default '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
show variables like "%char%";
set names utf8;
2.查看test数据库的编码格式:
mysql> show create database test;
3.查看yjdb数据表的编码格式:
mysql> show create table yjdb;
4,查看字段编码:
SHOW FULL COLUMNS FROM tbl_name;
设置数据库db_name默认为utf8:
ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
设置表tb_name默认编码为utf8:
ALTER TABLE `tb_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
ALTERTABLElogtestCONVERTTOCHARACTERSETutf8COLLATEutf8_general_ci;