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

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

WBOY
WBOYOriginal
2016-06-01 13:05:10914browse

创建数据库

最简单的方式:

代码如下:


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;

Statement:
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