alamide的笔记库「 87篇笔记 」「 小破站已建 0 天啦 🐶 」


MySQL-Base-Database

2023-03-10, by alamide

1.一些🍪

查询支持的编码集

SHOW CHARACTER SET LIKE 'utf%';
CharsetDescriptionDefault collationMaxlen
utf8UTF-8 Unicodeutf8_general_ci3
utf8mb4UTF-8 Unicodeutf8mb4_general_ci4
utf16UTF-16 Unicodeutf16_general_ci4
utf16leUTF-16LE Unicodeutf16le_general_ci4
utf32UTF-32 Unicodeutf32_general_ci4

2.创建数据库


CREATE DATABASE [数据库名];

CREATE DATABASE [数据库名] CHARACTER SET [字符集]; 

CREATE DATABASE IF NOT EXISTS [数据库名] CHARACTER SET [字符集]; 

3.使用数据库


SHOW TABLES FROM [数据库名];

SHOW DATABASES;

-- 显示当前使用的库名
SELECT DATABASE();

-- 显示建表语句
SHOW CREATE DATABASE [数据库名];

USE [数据库名];

4.修改数据库


-- 修改编码集
ALTER DATABASE [数据库名] CHARACTER SET [字符集];-- gbk, utf8, latin1, utf8mb4

DROP DATABASE [数据库名];

DROP DATABASE IF EXISTS [数据库名];

5.代码示例


DROP DATABASE IF EXISTS db03;

CREATE DATABASE IF NOT EXISTS db03 CHARACTER SET gbk;

ALTER DATABASE db03 CHARACTER SET utf8mb4;

SHOW CREATE DATABASE db03;

SHOW DATABASES;

USE db03;

SELECT DATABASE();

SHOW TABLES FROM db03;
Tags: DB - MySQL
~ belongs to alamide@163.com