当前位置:网站首页>mySql学习记录——二、mySql建表命令
mySql学习记录——二、mySql建表命令
2022-06-12 08:56:00 【不确定性因素】
建表命令
1.1登录
[[email protected]]# mysql -u root -p
Enter password:****** # 登录后进入终端
mysql> create DATABASE RUNOOB;
//创建
CREATE DATABASE 数据库名;
1.2创建数据库
CREATE TABLE table_name (column_name column_type);
mysqladmin -u root -p create <数据库名>
Enter password:******
1.3删除数据库
drop 命令删除数据库
drop database <数据库名>;
mysqladmin 删除数据库
mysqladmin -u root -p drop 数据库名
//查看数据看
desc emo
//展示行款
show linesize
//设置行款
set linesize 120
//设置列宽
col ename for a8
col sal for 999
/
mysql索引的意思
1.Unique设置不可重复字段(唯一索引);
2.Normal 加快查询速度(普通索引);
3.Full Text 文章段查询(全文索引);
索引方法

1.B-Tree
B-Tree是最常见的索引类型,所有值(被索引的列)都是排过序的,每个叶节点到跟节点距离相等。所以B-Tree适合用来查找某一范围内的数据,而且可以直接支持数据排序(ORDER BY)
B-Tree在MyISAM里的形式和Innodb稍有不同:
MyISAM表数据文件和索引文件是分离的,索引文件仅保存数据记录的磁盘地址
InnoDB表数据文件本身就是主索引,叶节点data域保存了完整的数据记录
2.HASH
1.仅支持"=",“IN"和”<=>"精确查询,不能使用范围查询:
由于Hash索引比较的是进行Hash运算之后的Hash值,所以它只能用于等值的过滤,不能用于基于范围的过滤,因为经过相应的Hash算法处理之后的Hash
2.不支持排序:
由于Hash索引中存放的是经过Hash计算之后的Hash值,而且Hash值的大小关系并不一定和Hash运算前的键值完全一样,所以数据库无法利用索引的数据来避免任何排序运算
3.在任何时候都不能避免表扫描:
由于Hash索引比较的是进行Hash运算之后的Hash值,所以即使取满足某个Hash键值的数据的记录条数,也无法从Hash索引中直接完成查询,还是要通过访问表中的实际数据进行相应的比较,并得到相应的结果
4.检索效率高,索引的检索可以一次定位,不像B-Tree索引需要从根节点到枝节点,最后才能访问到页节点这样多次的IO访问,所以Hash索引的查询效率要远高于B-Tree索引
5.只有Memory引擎支持显式的Hash索引,但是它的Hash是nonunique的,冲突太多时也会影响查找性能。Memory引擎默认的索引类型即是Hash索引,虽然它也支持B-Tree索引
mysql索引这三种,nomal最常用,full text一般在文章搜索使用,Unique一般表示不可重复使用
如何优化数据库:
1.选择唯一性索引
2.为经常需要排序、分组和联合操作的字段建立索引
3.为常作为查询条件的字段建立索引
4.限制索引的数目
5.尽量使用数据量少的索引
6.尽量使用前缀来索引
7.删除不再使用或者很少使用的索引
参考文章: https://www.cnblogs.com/maowenqiang/p/10383835.html
边栏推荐
- 2022.6.11-----leetcode. nine hundred and twenty-six
- [data storage] storage of floating point data in memory
- 2022.6.9-----leetcode.497
- [character set 8] char8_ t、char16_ t、char32_ t、wchar、char
- (p19-p20) delegate constructor (proxy constructor) and inheritance constructor (using)
- 2022 safety officer-c certificate special operation certificate examination question bank and simulation examination
- Graphic analysis of viewbox in SVG
- Chapter VI - procedures with multiple segments
- [advanced pointer 2] array parameter transfer & pointer parameter transfer & function pointer & function pointer array & callback function
- Unittest测试框架
猜你喜欢
![[character set 8] char8_ t、char16_ t、char32_ t、wchar、char](/img/ef/e57fb345b36c84d3585fca0568b0ee.png)
[character set 8] char8_ t、char16_ t、char32_ t、wchar、char

The database doesn't know what went wrong

清华大学数据挖掘笔记(一)

【指針進階三】實現C語言快排函數qsort&回調函數

Union selector

【字符集九】gbk拷贝到Unicode会乱码?

IDEA新版UI申请方法+无测试资格使用方法及相关介绍

About weights exercise

Notes used by mqtt (combined with source code)
![[essence] explain in detail the memory management mechanism in QT](/img/7d/0d83158c6b0574dd3b3547b47af67e.jpg)
[essence] explain in detail the memory management mechanism in QT
随机推荐
处理异常数据
第六章-包含多个段的程序
Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"
Installation of Shengxin R package
The newline character with in the string is converted to an array
第三章 寄存器 (内存访问)
Shell基本语法--数组
QT realizes multi screen and multi-resolution adaptation
Background color translucent
Flink传入自定义的参数或配置文件
Unittest测试框架
Encapsulate the amount input box component.
Difference between binary GB and gib
Summary of common character sets
进制GB和GiB的区别
About weights exercise
Build personal blog and web.
Chapter 3 registers (memory access)
Adjust SVG width and height
[sklearn] lightgbm