• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
灬伊天?
博客园    首页    新随笔    联系   管理    订阅  订阅

2-MySQL数据库编码uft-8

mysql> show variables like 'character%';

mysql> show variables like 'collation%';

mysql> status;

mysql> exit;

vim /etc/my.cnf

[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

init_connect='SET NAMES utf8'

[mysql]
default-character-set=utf8

[mysql.server]
default-character-set=utf8

[mysqld_safe]
default-character-set=utf8

[client]
default-character-set=utf8

:wq!

systemctl restart mysqld

mysql> show create database 数据库名;
mysql> show create table 表名;

设置默认编码为utf8:
set names utf8;

设置数据库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;

创建数据库的时候:

CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';

建表的时候:

CREATE TABLE `database_user`(
`ID` varchar(40) NOT NULL default '',
`UserID` varchar(40) NOT NULL default '',
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

创建数据库

create table cantus(
id int(10) not null auto_increment primary key,
song char(20) not null,
album char(20) not null,
number smallint(5) not null,
writer char(12) not null,
composer char(12) not null,
singing char(12) not null,
lyric varchar(2000) not null);

create table orders(
id int(10) not null auto_increment primary key,
song char(20) not null,
album char(20) not null,
num smallint(5) not null,
number smallint(5) not null)ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

posted @ 2016-08-25 18:15  灬伊天☂  阅读(236)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3