Home > Database > Mysql Tutorial > MySQL数据库的基本操作_MySQL

MySQL数据库的基本操作_MySQL

WBOY
Release: 2016-06-01 13:02:43
Original
998 people have browsed it

一、查看所有数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wms                |
+--------------------+
Copy after login
其中,前三者是数据库自带的三个库。

二、创建数据库的基本语法

1. CREATE DATABASE database_name; // database_name是要创建的数据库的名称,该名称不能与已经存在的数据库重名。

例如:

mysql> create database db_test;
Copy after login
2. 数据库创建好以后,可以使用 SHOW CREATE DATABASE声明查看数据库的定义。

例如:

mysql> show create database db_test\G;
*************************** 1. row ***************************
       Database: db_test
Create Database: CREATE DATABASE `db_test` /*!40100 DEFAULT CHARACTER SET latin1 */
Copy after login
3. 使用 SHOW DATABASES 命令查看所有数据库:
mysql> show databases;
+--------------------+
| Database   
        |
+--------------------+
| information_schema |
| db_test            |
| mysql              |
| performance_schema |
| wms                |
+--------------------+
Copy after login

三、删除数据库

1. 语法

DROP DATABASE database_name; //database_name为要删除的数据库的名称,如果该数据库不存在,则删除出错。

2. 示例

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db_test            |
| mysql              |
| performance_schema |
| wms                |
+--------------------+

mysql> drop database db_test;
Query OK, 0 rows affected (0.05 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wms                |
+--------------------+
Copy after login

3. 注意: 使用DROP DATABASE命令时要非常谨慎,在执行该命令时,MySQL不会给出任何提醒确认信息,DROP DATABASE删除数据库以后,数据库中存储的所有数据表和数据也一同被删除,而且不能恢复。

四、选择当前数据库
语法
USE database_name;

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

如果你们有更好的建议,请发邮件到我私人邮箱: david.louis.tian@outllook.com

版权@: 本文系本人原创,转载请标明出处,谢谢
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template