萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> 命令行建立Mysql數據庫的例子

命令行建立Mysql數據庫的例子

建立數據庫我們可以很多的方式來創建了,小編來為各位介紹使用命令行建立Mysql數據庫的例子,希望例子對各位有幫助.


命令行下建立不同字符集的數據庫、刪除數據庫:

[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>

copyright © 萬盛學電腦網 all rights reserved