7.1.1 创建数据库语法
create database database_name;
create database if not exists database_name;
7.2.1 查看MySQL中存在的数据库
show databases;
7.2.2 查看MySQL命令行所在数据库,切换数据库为mysql2
select database();
use mysql2;
7.2.3 查看数据库创建信息
show create database database_name;
show create database database_name \G;
7.3.1 通过重命名数据表修改数据库名称
create database if not exists test_old;
use test_old;
create database if not exists table_test(id int);
show tables;
create database if not exists test_new;
rename table test_old.table_test to test_new.table_test;
drop table if exists test_old;
use test_new;
show tables;
7.3.3 通过创建数据表修改数据库名称
create database if not exists test_new;
create table if not exists test_new.table_test like test_old.table_test;
drop database test_old;
use test_new;
show tables;
7.4.1 创建数据库时指定字符编码
create database [if not exists] database_name default character set character_name collate collate_name [default encryption='N'];
# 查看数据库默认字符编码
show variables like '%character_set_database%';
7.4.2 修改数据库字符编码
alter database database_name character set character_name collate collate_name;