MYSQL入门学习之八:数据库及表的基本操作
一、操作数据库
1、查看数据库
show databases [ like ''];
示例:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| luomian |
| mydb |
| mysql |
| net80576314 |
| phpcms_uat |
| phpcmsv9 |
| phpcmsv9_new |
| rutiao |
| szwalkers |
| test |
| v9test1 |
+--------------------+
mysql> show databases like 'php%';
+-----------------+
| Database (php%) |
+-----------------+
| phpcms_uat |
| phpcmsv9 |
| phpcmsv9_new |
+-----------------+
2、创建数据库
create database [if not exists] dbname;
示例:
mysql> create database if not exists mydb;
3、选择需要的数据库
use dbname
示例:
mysql> use mydb;
Database changed
4、删除数据库
drop database [if exists] dbname;
示例:
mysql> drop database if exists mydb;
二、操作表
1、显示表
show tables;
示例:
mysql> show tables;
+-----------------------+
| Tables_in_test |
+-----------------------+
| newname |
| productnotes |
| test_char |
| test_inn |
| test_inn2 |
| test_priority |
| test_trans |
| test_view |
+-----------------------+