MYSQL语句大全:数据库与表显示、创建、删除

2020-07-2817:41:38数据库教程Comments1,309 views字数 2599阅读模式

数据库显示

show databases;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| app_blogcurder     |
| auth_demo          |
| canzhieps          |
| cmsdemo            |
| mysql              |
| onethink           |
| performance_schema |
| ranzhi             |
| thinkems           |
| thinksns_3_1       |
| thinksns_4_0       |
+--------------------+
12 rows in set (0.01 sec)

创建数据库

create database 库名字;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

mysql> create database test;
Query OK, 1 row affected (0.00 sec)

删除数据库

drop database [IF EXISTS] 库名字;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

选中数据库

use 库名;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

mysql> use mysql
Database changed

mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.6.17, for Win64 (x86_64)

Connection id:          8
Current database:       mysql
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.6.17 MySQL Community Server (GPL)

显示表

数据表

show tables;[需要县选中数据库]文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
 ... ...

显示表结构

desc 表名; 或者 describe 表名;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

mysql> desc db;
+-----------------------+---------------+------+-----+---------+-------+
| Field                 | Type          | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host                  | char(60)      | NO   | PRI |         |       |
| Db                    | char(64)      | NO   | PRI |         |       |
| User                  | char(16)      | NO   | PRI |         |       |
 ... ...

表创建

CREATE TABLE `member` (
  `uid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
  `nickname` char(16) NOT NULL DEFAULT '' COMMENT '昵称',
  `sex` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '性别',
  `birthday` date NOT NULL DEFAULT '0000-00-00' COMMENT '生日',
  `qq` char(10) NOT NULL DEFAULT '' COMMENT 'qq号',
  `score` mediumint(8) NOT NULL DEFAULT '0' COMMENT '用户积分',
  `login` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '登录次数',
  `reg_ip` bigint(20) NOT NULL DEFAULT '0' COMMENT '注册IP',
  `reg_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间',
  `last_login_ip` bigint(20) NOT NULL DEFAULT '0' COMMENT '最后登录IP',
  `last_login_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后登录时间',
  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员状态',
  PRIMARY KEY (`uid`),
  KEY `status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='会员表';

表删除

drop table 表名;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19901.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/sjk/19901.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定