Mysql在终端的基本操作

show databases;
show tables;

create database baseName;
create table tableName (字段 类型 约束[,字段 类型 约束]);

show create database baseName;
show create table tableName;

use baseName;
desc tableName;

drop database baseName
drop table tableName;

alter table tableName add age datetime;
alter table tableName modify age date; 修改
alter table tableName change age aged date default ‘1990’;
alter table tableName drop age;

auto_increment 表示自动增长
not null 表示不能为空
primary key 表示主键
default 默认值
unsigend 无符号的类型
enum(“a”,“b”,“c”)

1.链接数据库

mysql -u root -p
mysql -u root -p pwd

2.退出数据库

exit/quit/ctrl + d

3.查看所有数据库

show databases;

4.显示时间

select now();

5.显示数据库版本

select version();

6.创建数据库

create database baseName;
create database baseName charset = utf8;

7.查看创建数据库的语句

show create database baseName;
在这里插入图片描述
默认方式创建的数据库编码格式是拉丁文

8.删除数据库

drop database baseName
这里需要说明一下,如果baseName的名字出现特殊字符,需要将名字作为一个整体,在名字外面加上` 这个点是键盘esc下面的那个点。

9.查看当前使用的数据库

select database();

10.进入数据库

use baseName;

》》》》》》》》》》》》》》》》》》》》》》》》》》表

11.查看当前数据库的所有表

show tables;

12.创建数据表

create table tableName (字段 类型 约束[,字段 类型 约束]);
create table tableName(id int primary kye not null auto_increment,name varchar(20));

auto_increment 表示自动增长
not null 表示不能为空
primary key 表示主键
default 默认值
unsigend 无符号的类型
enum(“a”,“b”,“c”)

13.进入表

desc tableName;

14.查看表的创建语句

show create table tableName;

》》》》》》》》》》》》》》》》》》》》》表的修改

  1. 添加字段

alter table tableName add age datetime;

16.修改表(不改字段名)

alter table tableName modify age date;

17.修改表(改字段名)

alter table tableName change age aged date default ‘1990’;

18.删除表字段

alter table tableName drop age;

19.删除表

drop table tableName;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值