数据库的选取,创建,丢弃和变更 数据表和索引的创建,变更和丢弃从数据表检索信息
先看看MySQL支持的SQL语句的分类1, 数据库的选取,创建,丢弃和变更
use
create database
drap database
alter database
2, 数据表和索引的创建,变更和丢弃
create table
drop table
create index
drop index
alter index
3, 从数据表检索信息
select
union
4, 事务处理
begin
commit
rollback
set autocommit
5, 对数据表里面的信息进行修改
delete
insert
load data
replace
update
6, 管理型命令
flush
grant
revoke
一,命名规则
1MySQL允许用在名字中的系统字符.
任何字母数字加上”_” 或 “$”
2名字的长度.
数据库,数据表,数据列,索引等名字最多64个字母
256别名最多256个字母
3名字的限定符
依据不同的上下文,有时需要给某些名字加上某个限制:如数据列的全限定,部分限定,以及无限制.这一点比较容易理解
select * from db_name.tbl_name…
二,MySQL中的大小写问题
关键字和函数名:不区别
数据库名数据表名:根据服务器主机系统而定
数据列名索引名:不区别
别名:区别大小写
一般来说,不管系统是否区分数据库名和数据表名中的字母大小写情况,我们都应该在同一个查询语句里面以前后一致的字母大小写形式来写出这些名字,这是一个非常好的编程习惯。
三,MySQL支持的名种数据表类型详解
1,ISAM数据表
这是3.23版本之前的MySQL支特的唯一一种表类型,目前己经过时,MyIASM处理程库逐步取代了ISAM处理程序,这种老式的表类型己经没有人在用了
2,MyIASM数据表
• 这是目前中MySQL默认使用的数据表类型。其优点是
• 如果主机操作系统支持大尺寸文件,数据表长度就能够很大,就能客纳更多的数据.
• 数据表内容独立于硬件也就是说可以把数据表在机器之间随意拷贝
• 提高了索引方面的功能
• 提供了更好的索引键压缩效果
• auto_incremnet能力加强
• 改进了对数据表的完整性检查机制
• 支持进行fulltext全文本搜索
3,Merge数据表
这是一种把相同结构的MyIASM数据表组织为一个逻辑单元的方法
4,HEAP数据表
这是一种使用内存的数据表,而且各个数据行的长度固定,这两个特性使得这种类型数据表的检索速度非常快,作为一种临时性的数据表,HEAP在某些特定情况下很有用。
5,BDB数据表
这种数据表支持事务处理机制
具有良好的并发性能
6,InnoBDB数据表
这是最近加入MySQL的数据表类型,有许多新的特性
支持事务处理机制
崩溃后能够立刻恢复
支持外键功能,包括级联删除
具有并发功能
7这种数据表在硬盘上的文件存储方式
IASM Frm isd ism
MyISAM Frm myd myi
Merge Frm mrg
Heap Frm
BDB Frm db
InnoBDB frm
8数据表的可移植性
通用方法:吧数据表的内容导出到一个文本文件中,然后拷贝到目的地硬盘上,在用脚本加载到数据库里面,这是首先我们应该掌握的方法。但就文件层次的操作来说,某些数据表是可以单独拷贝的。看表了
ISAM No
MyIASM Yes
BDB No
InnoBDB Yes
四,索引的初步知识
1,索引是加快数据表内容访问性能的基本手段,其基本特性:
为可以索引单独的数据列也可以构造包含多个数据列的复合索引
索引可以包含重复键值
可以为一个数据表建立多个索引
2,不同的数据表有着不同的索引特性使用的时候需要区别对待
3,如何创建索引
①用alter table命令创建索引
②用create index 命令创建索引
③在create table 时创建索引
五,变更数据表的结构
当发现某个数据表的结构己经不能满足我们的使用要求时,就要对其结构进行变更.可能需要这个数据表存放比以前更多的信息;也可能是这个数据表里面的某些信息己经没用;了或许是现有的某个数据列宽度太窄…在这些情况下都要用到alter 语匀
1,重新命名数据表
alter table A rename to B //数据表A改名为B
rename table A to B //数据表A改名为B
rename A toC,B to A,C to A //数据表A和数据表B互换名字
alter table S.A rename to T.A //数据库S里面的表A移动到数据库B里面
rename table S.A to T.A //数据库S里面的表A移动到数据库B里面
2,改变数据列的类型
我们现在要把数据表A里面的一个smallint unsigned类型的数据列I再次改动为 mediumint unsigned 类型
alter table A motify I mediumint unsigned
alter table A change I I mediumint unsigned
注意change子句的特点:不仅能够改变数据列的类型,还能改变数据列的名字。这是modify子句所不能完成的。下面就把这个数据列改名了。
alter table A change I J mediumint unsigned
3,将数据表由可变长度数据行转变成固定长度数据行
有的时候为了提高性能,需要做这样的转变,但有一点需要注意:必须用同一条alter命令来一次改变所有的数据列,不能仅仅改变一个数据列!举例如下:
create table A(name varchar(40),address varchar(80))
我们开始修改命令就应该是:
alter table A modify name char(40),modify address char(80);
4,将数据表由固定长度数据行转变成可变长度数据行
如果觉得空间利用率不高,那就需要再转变回来,这个就很简单了,没有特别要求
alter table A modify name varchar(40)
5,转换数据表类型
我们知道,MySQL数据库存在多种数据表类型,但每一种类型的特性并不相同。
如果你想让你的数据表支持事务处理机制。那就必须把它搞成BDB或innoBDB格式
alter table A type= BDB
alter table A type= InnoBDB

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.

InnoDB is suitable for applications that require transaction support and high concurrency, while MyISAM is suitable for applications that require more reads and less writes. 1.InnoDB supports transaction and bank-level locks, suitable for e-commerce and banking systems. 2.MyISAM provides fast read and indexing, suitable for blogging and content management systems.

There are four main JOIN types in MySQL: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN returns all rows in the two tables that meet the JOIN conditions. 2.LEFTJOIN returns all rows in the left table, even if there are no matching rows in the right table. 3. RIGHTJOIN is contrary to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet JOIN conditions.

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
