MySQL的字符集操作命令总结_MySQL
以下均在mysql 5.5命令行中运行通过:
查看MySQL支持的字符集:
show charset;
查看字符集:
status
下面的更具体:
SHOW VARIABLES LIKE 'character_set_%';
查看排序方式:
SHOW VARIABLES LIKE 'collation_%';
数据库建立时候一般会使用默认的字符集,除非在建立的时候指定:
CREATE DATABASE [db-name] CHARACTER SET utf8 COLLATE utf8_general_ci;
建立table时候指定字符集:
create table [table-name] (id int not null ) default charset utf8;
查看database使用的字符集:
方法1:找到存放数据库的目录,进入相应database的目录,查看db.opt文件。
方法2:
show create database [db-name];
查看表的字符集:
show create table [table-name];
查看数据库中每个表的字符集:
show table status from [db-name];
如果每一列后未说明字符集,则列的字符集和表一样。
也可以指定某个表:
show table status from [db-name] like '%filter%';
查看表中每一列的字符集:
show full columns from [table-name];
或者
show table status from [db-name];
修改数据库字符集:
ALTER DATABASE [db-name] DEFAULT CHARACTER SET [character-name] COLLATE [collation-name];
修改表和列(字段)的字符集:
ALTER TABLE [table-name] CONVERT TO CHARACTER SET [character-name] COLLATE [collation-name];
只是修改表的字符集:
ALTER TABLE [table-name] DEFAULT CHARACTER SET [character-name] COLLATE [collation-name];
其他: 可以修改mysql的默认字符集为自己需要的字符集,如utf-8,建表的时候表的字符集默认使用数据库的字符集。不过,个人觉得更好的方式是,在建立数据库时候制定数据库使用的字符集,我们在编写程序时候,也不要忽略这个查询:
SET NAMES 'utf8';

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)
