mysql学习笔记-基本语法-表结构创建

一、数据库连接

命令行工具 MysqL [-h 127.0.0.1][-p3306] -uroot -p xxxx

二、DLL语法

C:\Users>MysqL -uroot -p xxxx

MysqL> # 查询所有数据库
MysqL> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| itcast             |
| MysqL              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.00 sec)

MysqL> # 查询当前数据库
MysqL> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

MysqL> # 创建数据库
MysqL> CREATE DATABASE if not exists test default charset utf8;
Query OK, 1 row affected, 1 warning (0.02 sec)

MysqL> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| itcast             |
| MysqL              |
| performance_schema |
| sakila             |
| sys                |
| test               |
| world              |
+--------------------+
8 rows in set (0.00 sec)

MysqL> # 删除数据库,if exists 如果存在
MysqL> drop database if exists test;
Query OK, 0 rows affected (0.01 sec)

MysqL> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| itcast             |
| MysqL              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.00 sec)

MysqL> # 切换使用数据库use
MysqL> use itcast;
Database changed
MysqL> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| itcast     |
+------------+
1 row in set (0.00 sec)

# DDL 表创建

CREATE TABLE tb_uset(
	id int comment '编号',
	name varchar(50) comment '姓名',
	age int comment'年龄',
	gender varchar(1) comment '性别'
)comment '用户表';

MysqL> # 查询当前数据库所有表
MysqL> SHOW TABLES;
+------------------+
| Tables_in_itcast |
+------------------+
| tb_uset          |
+------------------+
1 row in set (0.00 sec)

MysqL> # 查询表结构
MysqL> DESC tb_uset;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int         | YES  |     | NULL    |       |
| name   | varchar(50) | YES  |     | NULL    |       |
| age    | int         | YES  |     | NULL    |       |
| gender | varchar(1)  | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

MysqL> # 查询指定表的建表语句
MysqL> SHOW CREATE TABLE tb_uset;
+---------+------------------------------------------------------+
| Table   | Create Table      |
+---------+------------------------------------------------------+
| tb_uset | CREATE TABLE `tb_uset` (
  `id` int DEFAULT NULL COMMENT '编号',
  `name` varchar(50) DEFAULT NULL COMMENT '姓名',
  `age` int DEFAULT NULL COMMENT '年龄',
  `gender` varchar(1) DEFAULT NULL COMMENT '性别'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户表' |
+---------+------------------------------------------------------+
1 row in set (0.00 sec)

 

相关文章

优化MySQL数据库发布系统存储的方法有:1.mysql库主从读写分...
使用mysql的方法:在“我的电脑”→右键→“管理”→“服务”...
在mysql中查看root用户权限的方法:1.命令行启动mysql服务;...
MySQL主从复制是用来备份一个与主数据库一样环境的从数据库,...
运行mysql的方法1.启动mysql服务,在“我的电脑”→右键→“...
开启mysql的方法1.可以通过快捷键win+r,输入cmd,打开窗口,...