search
HomeDatabaseMysql TutorialMySQL 服务器变量 数据操作DML-视图

SQL语言的组成部分

常见分类:

DDL:数据定义语言DCL:数据控制语言,如授权DML:数据操作语言

其它分类:

完整性定义语言:DDL的一部分功能约束约束:包括主键,外键,唯一键,条件,非空,事务等各类约束视图定义:即虚表,就是存储下来的SELECT语句事务控制嵌入式SQL和动态SQL

数据字典:系统编目(system catalog)

作用:保存数据库服务器上的元数据

保存元数据的数据库有:

information_schemamysqlperformance_schema

元数据包括

关系名称关系的各字段名称各字段的数据类型和长度约束关系上的视图名称及视图的定义授权用户名称用户的授权和帐户信息统计类的数据关系字段的个数关系中的行数关系的存储方法

SQL语言的数据类型及属性修饰符

字符型1:char,varchar,text等

# 对应可用属性修饰符:NOT NULL:非空约束NULL:允许为空DEFAULT ‘string’:默认值,不适用于text类型CHARACTER SET ‘字符集’:设定字符集查看当前MySQL字符集:show variables like ‘%char%’;查看可使用字符集:show character set;COLLATION:设定字符集的排序规则查看可用排序规则:show collation;

字符型2:binary,varbinary,blob等

# 对应可用属性修饰符NOT NULL,NULLDEFAULT:不适用于blob类型

整型

# 对应可用属性修饰符:AUTO_INCREMENT:自动增长(前提:非空、唯一,支持索引,非负值)UNSIGNED:无符号NOT NULL,NULLDEFAULT

浮点型

# 对应可用属性修饰符:NOT NULL,NULLDEFAULTUNSIGNED

日期时间型

# 对应可用属性修饰符:NOT NULL,NULLDEFAULT

内置类型

# ENUM和SET的区别ENUM:枚举,一般存储字串,只能取其中一个使用SET:集合,一般存储单个字符,可组合各字符形成字串使用# 对应可用属性修饰符:NOT NULL,NULLDEFAULT

MySQL中的服务器变量

支持修改的服务器变量

# 一般分类动态变量:可在MySQL运行时修改静态变量:在配置文件中修改其值,其重启后方能生效# 从其生效范围来分类全局变量:服务器级别,修改之后仅对新建立的会话有效会话变量:会话级别,仅对当前会话有效;会话建立时,从全局继承各变量

查看服务器变量

# 一般分类动态变量:可在MySQL运行时修改静态变量:在配置文件中修改其值,其重启后方能生效# 从其生效范围来分类全局变量:服务器级别,修改之后仅对新建立的会话有效会话变量:会话级别,仅对当前会话有效;会话建立时,从全局继承各变量

修改服务器变量

# 前提:默认仅管理员有权限修改全局变量set {global|session} Variable_Name=’Value’;# 注:无论是全局还是会话级别的动态变量修改,在重启mysqld后都会失效;若想永久生效,可定义在配置文件中的相应段中[mysqld]

MySQL中的数据操作

数据库操作

wKiom1NPF8vwKKU_AAPKpcatHQg162.jpg

表操作

创建表

wKioL1NPF-OCFlu6AA63m-UncI8811.jpg

删除表

wKiom1NPGBujtIAIAAG16GQu_dI321.jpg

修改表结构

wKiom1NPGCiSgK09ABFJy1D8s-U530.jpg

数据操作

包括插入(Insert)替换(Replace)更新(Update)删除(Delete)操作

wKioL1NPF8_Rvaq6AApoQExArMI842.jpg

MySQL的视图

本质:视图就是存储下来的select语句

创建视图

create view View_Name as select_clause# 如 create view stu as select Name,Age,ClassID from students;

显示视图的创建属性

show create view stu;

使用:授权用户权限时,只指定视图,则用户只能查看到视图内的内容,而不能查看全部数据了

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

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),