建立資料庫
最簡單的方式
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;