命令行下建立不同字符集的数据库、删除数据库:
[root@lamp ~]# /usr/local/mysql/bin/mysql -uroot -p'admin123'
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.16 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
mysql> create database byrd_default; #建议一个叫做byrd_default的数据库
Query OK, 1 row affected (0.08 sec)
mysql> show databases like 'byrd%'; #查看以byrd开头的数据库,
+------------------+
| Database (byrd%) |
+------------------+
| byrd_default |
+------------------+
1 row in set (0.00 sec)
mysql> show create database byrd_default; #查看系统建立byrd_default命令,byrd_default默认编码是utf8,因为我编译mysql的时候设置的默认编码为utf8
+--------------+-----------------------------------------------------------------------+
| Database | Create Database |
+--------------+-----------------------------------------------------------------------+
| byrd_default | CREATE DATABASE `byrd_default` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+--------------+-----------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> create database gbk default character set gbk collate gbk_chinese_ci; #建立一个名字叫做gbk,编码方式是gbk的数据库
Query OK, 1 row affected (0.00 sec)
mysql> show create database gbk;
+----------+-------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------+
| gbk | CREATE DATABASE `gbk` /*!40100 DEFAULT CHARACTER SET gbk */ |
+----------+-------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show databases; #所有数据库表
+--------------------+
| Database |
+--------------------+
| information_schema |
| byrd_default |
| gbk |
| gbk1 |
| gbk2 |
| gbk3 |
| gbk4 |
| mysql |
| performance_schema |
| test |
| ultrax |
+--------------------+
11 rows in set (0.00 sec)
mysql> drop database gbk1; #删除名字为gbk1的数据库
Query OK, 0 rows affected (0.19 sec)
mysql> drop database gbk2;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database gbk3;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database gbk4;
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| byrd_default |
| gbk |
| mysql |
| performance_schema |
| test |
| ultrax |
+--------------------+
7 rows in set (0.00 sec)
mysql> drop database if exists byrd_default; #如果byrd_default的数据库存在则删除,如果不存在则提示警告
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gbk |
| mysql |
| performance_schema |
| test |
| ultrax |
+--------------------+
6 rows in set (0.00 sec)
mysql>