mysql数据库操作:http://www.cnblogs.com/ggjucheng/archive/2012/11/02/2751840.html
创建数据库
最简单的方式
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;