相关文章链接:
观前提示:
本文所使用的Linux版本为CentOS release 6.10,mysql版本为8.0.16。
1.登录MySQL
在安装的mysql的bin目录下执行命令
mysql -u user_name -p
输入密码登录系统
2.创建数据库
执行命令
create database db_name charset utf8 collate utf8_general_ci;
查看编码排序
select * from information_schema.schemata where schema_name = 'db_name';
3.执行sql脚本
sql脚本如下
选择数据库
use db_name
执行命令
source 路径/脚本.sql
查看表
show tables;
补充
修改表字符集和排序
-- 修改数据库字符集和排序规则
alter database db_name character set utf8 collate utf8_general_ci;
-- 查看数据库的字符集
select * from information_schema.schemata where schema_name = 'db_name';
-- 修改表默认的字符集
alter table table_name character set gbk collate gbk_bin;
-- 修改表数据的字符集
alter table table_name convert to character set gbk collate gbk_bin;
-- 查看表的字符集
select * from information_schema.tables where table_schema = 'db_name' and table_name = 'table_name';
-- 修改字段的字符集
alter table table_name change column_name varchar(50) character set gbk collate gbk_bin;
-- 查看字段的字符集
select * from information_schema.columns where table_schema = 'db_name' and table_name = 'table_name';