一、SQL:结构化查询语言
SQL(Structured Query Language)是高级的非过程化变成语言,专门用于查询和修改数据库的信息以及对数据库进行管理和维护的标准语言。SQL语言结构简单,功能强大,得到了众多DBMS的支持。
SQL分为四个部分:
数据定义语言(DDL):用于定义和管理数据对象,包括数据库、数据表等。如create/drop/alter等
数据操作语言(DML):操作数据库对象中包含的数据,如insert/update/delete等
数据查询语言(DQL):查询数据库对象中包含的数据,并返回数据结果,如select
数据控制语言(DCL):管理数据库对象,包括权限管理和数据更改,如grant/revoke/commit/rollback等
二、MySQL的常见操作
1、连接和关闭:mysql –h 【服务器主机地址】-u 用户名 –p 用户密码 quit和exit用于关闭连接
2、创建用户和授权:GRANT 权限 ON 数据库.数据表 TO 用户名@登陆主机 IDENTIFIED BY “密码”
<span id="lnum1" style="font-size: 14px; color: rgb(96, 96, 96);"> 1:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//添加新用户,名为phper 密码dwqs,在任何主机登陆,对所有数据库拥有查询、插入、修改、删除权限</span></span>
<span id="lnum2" style="font-size: 14px; color: rgb(96, 96, 96);"> 2:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//创建用户前,先以root用户登陆</span></span>
<span id="lnum3" style="font-size: 14px; color: rgb(96, 96, 96);"> 3:</span><span style="font-size: 14px;"> GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO phper<span style="color: rgb(0, 96, 128);">@"%"</span> IDENTIFIED BY <span style="color: rgb(0, 96, 128);">"dwqs"</span></span>
<span id="lnum4" style="font-size: 14px; color: rgb(96, 96, 96);"> 4:</span><span style="font-size: 14px;"> </span>
<span id="lnum5" style="font-size: 14px; color: rgb(96, 96, 96);"> 5:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//只对mydb数据库创建用户并授权</span></span>
<span id="lnum6" style="font-size: 14px; color: rgb(96, 96, 96);"> 6:</span><span style="font-size: 14px;"> GRANT SELECT,INSERT,UPDATE,DELETE ON mydb.* TO phper@localhost IDENTIFIED BY <span style="color: rgb(0, 96, 128);">"dwqs"</span></span>
3、数据库操作
<span id="lnum1" style="font-size: 14px; color: rgb(96, 96, 96);"> 1:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//创建名为test的数据库</span></span>
<span id="lnum2" style="font-size: 14px; color: rgb(96, 96, 96);"> 2:</span><span style="font-size: 14px;"> create database [<span style="color: rgb(0, 0, 255);">if</span> not exists] test;</span>
<span id="lnum3" style="font-size: 14px; color: rgb(96, 96, 96);"> 3:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//删除test</span></span>
<span id="lnum4" style="font-size: 14px; color: rgb(96, 96, 96);"> 4:</span><span style="font-size: 14px;"> drop database [<span style="color: rgb(0, 0, 255);">if</span> exists] test</span>
<span id="lnum5" style="font-size: 14px; color: rgb(96, 96, 96);"> 5:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//显示数据库列表</span></span>
<span id="lnum6" style="font-size: 14px; color: rgb(96, 96, 96);"> 6:</span><span style="font-size: 14px;"> show databases</span>
<span id="lnum7" style="font-size: 14px; color: rgb(96, 96, 96);"> 7:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//使用test数据库</span></span>
<span id="lnum8" style="font-size: 14px; color: rgb(96, 96, 96);"> 8:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 0, 255);">use</span> test</span>
4、数据表操作
<span id="lnum1" style="font-size: 14px; color: rgb(96, 96, 96);"> 1:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//在test中创建一个表,表名是dwqs</span></span>
<span id="lnum2" style="font-size: 14px; color: rgb(96, 96, 96);"> 2:</span><span style="font-size: 14px;"> create table dwqs </span>
<span id="lnum3" style="font-size: 14px; color: rgb(96, 96, 96);"> 3:</span><span style="font-size: 14px;"> </span>
<span id="lnum4" style="font-size: 14px; color: rgb(96, 96, 96);"> 4:</span><span style="font-size: 14px;"> id <span style="color: rgb(0, 0, 255);">int</span> not <span style="color: rgb(0, 0, 255);">null</span> auto_increment,</span>
<span id="lnum5" style="font-size: 14px; color: rgb(96, 96, 96);"> 5:</span><span style="font-size: 14px;"> name varchar(20) not <span style="color: rgb(0, 0, 255);">null</span> <span style="color: rgb(0, 0, 255);">default</span> <span style="color: rgb(0, 96, 128);">''</span>,</span>
<span id="lnum6" style="font-size: 14px; color: rgb(96, 96, 96);"> 6:</span><span style="font-size: 14px;"> site varchar(20) not <span style="color: rgb(0, 0, 255);">null</span> <span style="color: rgb(0, 0, 255);">default</span> <span style="color: rgb(0, 96, 128);">'www.ido321.com,</span></span>
<span id="lnum7" style="font-size: 14px; color: rgb(96, 96, 96);"> 7:</span><span style="font-size: 14px;"> email varchar(15) not null default ''</span>
<span id="lnum8" style="font-size: 14px; color: rgb(96, 96, 96);"> 8:</span><span style="font-size: 14px;"> ></span>
<span id="lnum1" style="font-size: 14px; color: rgb(96, 96, 96);"> 1:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//查看在test数据库的中表</span></span>
<span id="lnum2" style="font-size: 14px; color: rgb(96, 96, 96);"> 2:</span><span style="font-size: 14px;"> show tables</span>
<span id="lnum3" style="font-size: 14px; color: rgb(96, 96, 96);"> 3:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//查看dwqs表的结构</span></span>
<span id="lnum4" style="font-size: 14px; color: rgb(96, 96, 96);"> 4:</span><span style="font-size: 14px;"> desc dwqs 或 description dwqs</span>
<span id="lnum5" style="font-size: 14px; color: rgb(96, 96, 96);"> 5:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//删除dwqs表</span></span>
<span id="lnum6" style="font-size: 14px; color: rgb(96, 96, 96);"> 6:</span><span style="font-size: 14px;"> drop table dwqs</span>
5、数据表的内容管理
<span id="lnum1" style="font-size: 14px; color: rgb(96, 96, 96);"> 1:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//插入记录</span></span>
<span id="lnum2" style="font-size: 14px; color: rgb(96, 96, 96);"> 2:</span><span style="font-size: 14px;"> insert [into] 表名 [(字段名1),(字段名2),...,(字段名n)] values (<span style="color: rgb(0, 96, 128);">'值1'</span>,<span style="color: rgb(0, 96, 128);">'值2'</span>,...,<span style="color: rgb(0, 96, 128);">'值n'</span>)</span>
<span id="lnum3" style="font-size: 14px; color: rgb(96, 96, 96);"> 3:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//更新记录</span></span>
<span id="lnum4" style="font-size: 14px; color: rgb(96, 96, 96);"> 4:</span><span style="font-size: 14px;"> update 表名 set 字段名1=表达式1[,字段名2=表达式2,...,字段名n=表达式n]</span>
<span id="lnum5" style="font-size: 14px; color: rgb(96, 96, 96);"> 5:</span><span style="font-size: 14px;"> [where 条件] [order by 字段] [limit 行数]</span>
<span id="lnum6" style="font-size: 14px; color: rgb(96, 96, 96);"> 6:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//删除记录</span></span>
<span id="lnum7" style="font-size: 14px; color: rgb(96, 96, 96);"> 7:</span><span style="font-size: 14px;"> delete from 表名 [where 条件] [order by 字段] [limit 行数]</span>
<span id="lnum8" style="font-size: 14px; color: rgb(96, 96, 96);"> 8:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//查询记录</span></span>
<span id="lnum9" style="font-size: 14px; color: rgb(96, 96, 96);"> 9:</span><span style="font-size: 14px;"> select [all|distinct]</span>
<span id="lnum10" style="font-size: 14px; color: rgb(96, 96, 96);"> 10:</span><span style="font-size: 14px;"> {*|table.*|[table.]field1[AS alias1],[table.]field2[AS alias2][,...]}</span>
<span id="lnum11" style="font-size: 14px; color: rgb(96, 96, 96);"> 11:</span><span style="font-size: 14px;"> from tablaname[,...][in externaldatabase]</span>
<span id="lnum12" style="font-size: 14px; color: rgb(96, 96, 96);"> 12:</span><span style="font-size: 14px;"> [where 条件][group by 字段][having 条件][order by 字段][limit 行数]</span>
说明:在查询中,distinct用于排除重复的数据,只返回一个,默认是all。 as用于给列标记别名: 字段名 as ‘别名’,在查询的结果中,字段名以别名显示.in用于子查询,也可以使用like进行模糊查询,如 like ‘%php%’—>包含php字样的,%表示0个或任意个字符;like ‘dw_s’—>形如dwqs,dwrs等,_表示一个任意字符。group by是对查询结果分组。同时可以再select中嵌入SQL表达式或者函数,如count();
6、修改表
<span id="lnum1" style="font-size: 14px; color: rgb(96, 96, 96);"> 1:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//这个"修改"主要修改表的结构,如添加字段、修改字段属性等</span></span>
<span id="lnum2" style="font-size: 14px; color: rgb(96, 96, 96);"> 2:</span><span style="font-size: 14px;"> alter table 表名 action</span>
<span id="lnum3" style="font-size: 14px; color: rgb(96, 96, 96);"> 3:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//action的具体内容</span></span>
<span id="lnum4" style="font-size: 14px; color: rgb(96, 96, 96);"> 4:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//添加新字段</span></span>
<span id="lnum5" style="font-size: 14px; color: rgb(96, 96, 96);"> 5:</span><span style="font-size: 14px;"> alter table 表名 add 字段名 描述 [first|after 列名]</span>
<span id="lnum6" style="font-size: 14px; color: rgb(96, 96, 96);"> 6:</span><span style="font-size: 14px;"> alter table dwqs add qq <span style="color: rgb(0, 0, 255);">int</span>[14] not <span style="color: rgb(0, 0, 255);">null</span> <span style="color: rgb(0, 128, 0);">//为dwqs表添加一个qq字段,类型是整数,不为空</span></span>
<span id="lnum7" style="font-size: 14px; color: rgb(96, 96, 96);"> 7:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//修改字段</span></span>
<span id="lnum8" style="font-size: 14px; color: rgb(96, 96, 96);"> 8:</span><span style="font-size: 14px;"> alter table 表名 change(modify) 列表 描述</span>
<span id="lnum9" style="font-size: 14px; color: rgb(96, 96, 96);"> 9:</span><span style="font-size: 14px;"> alter table dwqs change qq qq varchar(15) <span style="color: rgb(0, 0, 255);">default</span> 0 <span style="color: rgb(0, 128, 0);">//将qq字段的类型改为varchar,默认值是0</span></span>
<span id="lnum10" style="font-size: 14px; color: rgb(96, 96, 96);"> 10:</span><span style="font-size: 14px;"> alter table dwqs modify qq varchar(15) <span style="color: rgb(0, 0, 255);">default</span> 0 <span style="color: rgb(0, 128, 0);">//将qq字段的类型改为varchar,默认值是0</span></span>
<span id="lnum11" style="font-size: 14px; color: rgb(96, 96, 96);"> 11:</span><span style="font-size: 14px;"> <span style="color: rgb(0, 128, 0);">//修改表名</span></span>
<span id="lnum12" style="font-size: 14px; color: rgb(96, 96, 96);"> 12:</span><span style="font-size: 14px;"> alter table 旧表名 rename <span style="color: rgb(0, 0, 255);">as</span> 新表名</span>
说明:[first|after 列名]表名新字段的位置,first将字段插入第一列,after 列名将字段插入到指定列名之后。未指定该值,默认在末尾添加。
modify和change的区别:change除了更改类型,还会更改列名,所有qq字段出现了两次,前一个是旧列名,后一个是新列名。而modify 没有修改列名的功能,所有qq只出现了一次

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于索引优化器工作原理的相关内容,其中包括了MySQL Server的组成,MySQL优化器选择索引额原理以及SQL成本分析,最后通过 select 查询总结整个查询过程,下面一起来看一下,希望对大家有帮助。

sybase是基于客户/服务器体系结构的数据库,是一个开放的、高性能的、可编程的数据库,可使用事件驱动的触发器、多线索化等来提高性能。

visual foxpro数据库文件是管理数据库对象的系统文件。在VFP中,用户数据是存放在“.DBF”表文件中;VFP的数据库文件(“.DBC”)中不存放用户数据,它只起将属于某一数据库的 数据库表与视图、连接、存储过程等关联起来的作用。

数据库系统由4个部分构成:1、数据库,是指长期存储在计算机内的,有组织,可共享的数据的集合;2、硬件,是指构成计算机系统的各种物理设备,包括存储所需的外部设备;3、软件,包括操作系统、数据库管理系统及应用程序;4、人员,包括系统分析员和数据库设计人员、应用程序员(负责编写使用数据库的应用程序)、最终用户(利用接口或查询语言访问数据库)、数据库管理员(负责数据库的总体信息控制)。

microsoft sql server是Microsoft公司推出的关系型数据库管理系统,是一个全面的数据库平台,使用集成的商业智能(BI)工具提供了企业级的数据管理,具有使用方便可伸缩性好与相关软件集成程度高等优点。SQL Server数据库引擎为关系型数据和结构化数据提供了更安全可靠的存储功能,使用户可以构建和管理用于业务的高可用和高性能的数据应用程序。

结构层次是“数据库→数据表→记录→字段”;字段构成记录,记录构成数据表,数据表构成了数据库。数据库是一个完整的数据的记录的整体,一个数据库包含0到N个表,一个表包含0到N个字段,记录是表中的行。

go语言可以写数据库。Go语言和其他语言不同的地方是,Go官方没有提供数据库驱动,而是编写了开发数据库驱动的标准接口,开发者可以根据定义的接口来开发相应的数据库驱动;这样做的好处在于,只要是按照标准接口开发的代码,以后迁移数据库时,不需要做任何修改,极大方便了后期的架构调整。

mysql查询为什么会慢,关于这个问题,在实际开发经常会遇到,而面试中,也是个高频题。遇到这种问题,我们一般也会想到是因为索引。那除开索引之外,还有哪些因素会导致数据库查询变慢呢?


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Dreamweaver Mac版
시각적 웹 개발 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

드림위버 CS6
시각적 웹 개발 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

뜨거운 주제



