MySQL 基本语句
- 显示数据库列表:show databases;
- 显示库中的数据表:show tables;
- 显示数据表的结构:describe 表名;
- 创建数据库:create database 库名;
- 删除数据库:drop database 库名;
- 创建表:create table 表名;
- 删除表:drop table 表名;
- 显示表中的记录:select * from 表名
- 插入数据:insert into <表名> [字段名1,字段名2,……字段名n] values (值1,值2,…值n )
- 修改数据:update 表名 set 字段名 = 新内容
- 使用数据库:use 数据库名
- 增加主键:alter table 表名 add primary key;
- 删除主键:alter table 表名 drop primary key;
- 列名:select
- 查询:from
- 分组:group by
- 排序:order by
- 去除重复数据:distinct
- 重命名数据库:alter table 表名 rename 新表名
- 删除表中所有记录:delete from表名
- 删除整张表:drop table 表名
- 删除满足条件的数据:delete from 表名where条件
- 平均值:average
- 求和:sum
- 总计:count
- 最大值:MAX
- 升序:ASC
- 降序:DESC
- 整形:integer
- 单精度浮点形:float
- 双精度浮点型:double
- 变长字符串:varchar
- 将字符转换为大写:ucase
- 返回绝对值:ABS
- 取余:Mod
- 设置UTF8 编码:set names utf8
- 设置版本号:version
- 左连接:left join
- 右链接:right join
- 内连接:inner join
- 主键索引:primary key
- 唯一索引:unique key
- 普通索引: key或index
- 外键约束:foreign key
- 清空表数据:truncate表名
- 对字符串进行加密:password()
- 取字符长度:length
- 删除索引:drop index索引名 on 表名
- 查看错误信息:show warnings
- 删除用户名:drop user
- 检查: check
- 命令:command
- 转换:convert
- 创建:create
- 默认:default
- 拒绝:deny
- 退出:exit
- 说明解释:explain
- 函数:function
- 日志文件:logging
- 查看版本号: select version();
- 查看当前数据库名: show databases();
- 查看用户名: show user();
- 查看当前数据库名: show current_user();
- 查看系统用户名; show system_user();
- 查看数据库路径: show @@datadir;
- 查看操作系统版本: show @@version_compile_os;
数据库实验
--显示已有的数据表:mysql> show databases;
--创建数据库:mysql> create database yjq;
--显示创建的数据库:mysql> show databases;
--使用创建成功的数据库:mysql> use yjq
--在数据库里创建学生表:mysql> create table student
--显示创建的表:mysql> show tables;
--创建教师表:mysql> create table teacher
--显示创建的表:mysql> show tables;
--创建课程表:Create table course
--显示创建的表:mysql> show tables;
--创建成绩表:Create table score
--显示创建的表:show tables: