Home > Database > Mysql Tutorial > MySQL数据库操作常用命令小结

MySQL数据库操作常用命令小结

WBOY
Release: 2016-06-07 16:27:29
Original
1290 people have browsed it

创建数据库 最简单的方式: CREATE DATABASE my_db; 或者是: CREATE DATABASE IF NOT EXISTS my_db; 创建utf8编码的数据库: CREATE DATABASE IF NOT EXISTS my_db default character set utf8 COLLATE utf8_general_ci; 那么在这个数据库下创建的所有数据

创建数据库

最简单的方式:


CREATE DATABASE  my_db;

或者是:


CREATE DATABASE IF NOT EXISTS my_db;

创建utf8编码的数据库:


CREATE DATABASE IF NOT EXISTS my_db default character set utf8 COLLATE utf8_general_ci;

那么在这个数据库下创建的所有数据表的默认字符集都会是utf8了,注意后面这句话 "COLLATE utf8_general_ci",大致意思是在排序时根据utf8变码格式来排序。

查看数据库列表:


show databases;

使用数据库:


use my_db;

查看数据库默认编码:


show variables like 'character_set_%'

+--------------------------+-------------------------------------------------------+
| Variable_name            | Value                                                 |
+--------------------------+-------------------------------------------------------+
| character_set_client     | utf8                                                  |
| character_set_connection | utf8                                                  |
| character_set_database   | latin1                                                |
| character_set_filesystem | binary                                                |
| character_set_results    | utf8                                                  |
| character_set_server     | latin1                                                |
| character_set_system     | utf8                                                  |
| character_sets_dir       | /usr/local/mysql-5.5.28-linux2.6-i686/share/charsets/ |
+--------------------------+-------------------------------------------------------+

可以看到character_set_database是lantin1.

修改数据库编码:


alter database my_db character set latin1;

删除数据库:


drop database my_db;

或者是:


drop database IF EXISTS my_db;

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template