mysql 创建数据库/表/字段

1、查询所有数据库

mysql > show databases;

2、创建数据库 school

mysql > create database school;

3、进入school 数据库

mysql > use school;

4、显示当前数据库

mysql > select database();
+------------+
| database() |
+------------+
| school     |
+------------+
1 row in set (0.00 sec)

5、创建空表 student

mysql > create table student;

6、创建带字段的表 student (id,name,age)

扫描二维码关注公众号,回复: 6125969 查看本文章

(1) id 整型 主建 不能为空 自动增长

(2) name 字符型 不能为空

(3) age 整型 不能为空 默认18

mysql > create table student(

           > id int primary key not null auto_increment,

           > name varchar(50) not null,

           > age int not null default 18

           >);

7、查询所有表

mysql > show tables;

8、查询表结构

mysql > desc student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(50) | NO   |     | NULL    |                |
| age   | int(11)     | NO   |     | 18      |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

9、查询表的详细信息

mysql > show create table student\G;

*************************** 1. row ***************************
       Table: student
Create Table: CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `age` int(11) NOT NULL DEFAULT '18',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

ERROR:
No query specified

猜你喜欢

转载自blog.csdn.net/mshxuyi/article/details/88046146
今日推荐