MySQL语言语法关键字总结

MySQL常用操作命令语法

数据定义语言,DDL DML 数据操作语言
显式数据 show databases
use 数据库名
create datebase ***
drop database 数据库名
表格操作
show tables
显式 show tables from 数据库名/show table ***
创建 create table ***(-------)
删除 drop table ***
内容操作
查看结构 desc **
添加 alter table 表名称 add 字段名 数据类型 after *** insert into 表名称(部分字段列表,) values (值列表)…
删除 alter table 表名称 drop 字段名 delete from 表名称 where 条件
truncate 表名称
修改类型 alter table 表名称 modify 字段名 新数据类型
修改列名 alter table 表名称 modify 旧名称 新名称 新类型
修改列位置 alter table 表名称 modify 字段名 数据类型 after ***
alter table 旧表名 rename 新表名
修改数据 update 表名称 set 字段一 = **… where 条件
约束与索引
添加约束 alter table 表名称 modify 字段名 类型 键名
添加约束(主键) alter table 表名称 add PRIMARY KEY(字段名)
删除约束 alter table 表名称 modify 字段名 类型
删除约束(主键) alter table 表名称 drop PRIMARY KEY
查看约束 show create table 表名;
查看索引 show index from 表名称;
查找 select distinct (***) from 表名称 where 条件 order by asc/desc
查询总结 SELECT 列名 FROM 表名 WHERE 条件 GROUP BY 分组 HAVING 过滤条件 ORDER BY 排序列 LIMIT 起始行,总条数
数据导出 mysqldump -h主机地址 -P端口号 -u用户名 -p密码 数据名 > 文件路径/文件名.sql
数据导入 source sql脚本路径名.sql
身份认证 用户名@主机号:root@localhost、 root@%、chailinyan@%
创建用户 CREATE USER ‘用户名’@‘主机IP地址’ IDENTIFIED BY ‘123456’;
删除用户 drop user ‘用户名’@‘主机IP地址’;

猜你喜欢

转载自blog.csdn.net/qq_38705144/article/details/110621726
今日推荐