数据库基本操作
1、进入数据库
win+R快捷键进入cmd命令中,输入 mysql -u root -p 回车
系统会提示输入passsward ,输入你的密码进入即可
创建数据库:
这里有三种命令
create database test;
create database if not exists test2;
create database if not exists test3 character set utf8mb4;
推荐使用第三种
使用数据库
use 数据库名称;
显示当前数据库
show databases;
删除数据库
drop database test;
表操作
需要操作表的时候,需要先试用该数据库;
use test;
查看表的结构:
desc stu;
mysql> desc stu;
+----------+---------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------+------+-----+-------------------+-----------------------------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| password | varchar(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| birthday | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| amount | decimal(11,2) | YES | | NULL | |
| resume | text | YES | | NULL | |
+----------+---------------+------+-----+-------------------+----------------