HomeDatabaseMysql Tutorialmysql十分全的和完整的总结

mysql非常全的和完整的总结 (1)数据类型 类型 备注 tinyint/smallint/mediumint/int/bigint 1B/2B/3B/4B/8B float/double 单精度/双精度浮点型 decimal 不会产生精度丢失的单精度/双精度浮点型 date 日期类型 time 时间类型 datetime/ TimeStamp 日期时间类型

mysql非常全的和完整的总结


(1)数据类型

类型

备注

tinyint/smallint/mediumint/int/bigint

1B/2B/3B/4B/8B

float/double

单精度/双精度浮点型

decimal

不会产生精度丢失的单精度/双精度浮点型

date

日期类型

time

时间类型

datetime/TimeStamp

日期时间类型/TimeStamp(登录时间,自动填充)

year

年类型

char

定长字符串类型

varchar

可变长字符串类型

tinyblob/blob/mediumblob/longblob

255B/64K/16M/4G大小图片/音乐二进行数据

tinytext/text/mediumtext/longtext

255B/64K/16M/4G大小的文本数据


(2)mysql小知识

①登录

mysql > mysql -u root -p回车   

           ****回车

   mysql > exit回车


②创建/使用/查看/删除数据库

   create database 数据库名;(以分号结束),SQL命令大小写无关   

   show databases; 

   use 数据库名;

 

③修改/备份/恢复数据库数据

备份:c:\> mysqldump -u root -p mydb2 > d:\mydb2.sql回车(可无分号结束)密码回车

注意:该SQL命令是MySQL特有的,必须是MySQL环境外执行,即WindowXp环境中执行(退出mysql平台)

恢复:mysql:\> source d:\mydb2.sql;回车(需要分号结束)

注意:该SQL命令是MySQL特有的,必须是MySQL环境中执行。

 

④MySQL支持数据类型简介

(1)Date/Datetime/TimeStamp,定界符使用''或"",但部份数据库可能不支持"",优先推荐''作为定界符,对于日期类型,MySQL数据库有一个的判段-功能

(2)varchar(变长)/char(定长)

(3)Text(大于65536字符的数据)/Blob(存储二进制多媒体数据,例如Mp3等),该二类型都有四个子类型,根据存储内容的大小进行选择

(4)INT型有带符号和无符号之分,int(5)表示int默认为5位,如果插入id值,小于5位,左补空格,如果插入id值,大于5位,按照插入值,但必须满足int类型的大小确定

(5)FLOAT(M,D),D表示小数点后的D位,按四舍五入计算,M表示除小数点外的所有位数总和

⑤MySQL修改表和字符集

 

show variables like 'character%';

set character_set_results=gbk;

(3)MySQL解决中文乱码(XP下)

2种解决方法:

a)在当前MySQL客户端修改输入和输出的MySQL环境变量为GBK或GB2312,注意,该种方式只在当前窗口中有效

b)修改MySQL目录下的my.ini文件,将客户端的缺省编码方式改为GBK或GB2312,注意,需要重新启动MySQL服务

(4)表的增删改操作

a)insert 

b)update

c)delete from 或truncate table或drop table

delete from:按行删除表中的所有记录,但会保留表,适合删除数据量不大数据,可按条件删除

truncate table:复制原表结构-〉一次性删除整表 -> 自动恢复原表结构,适合删除数据量较大数据,不能按条件删除

drop table:删除表本身

删除记录时,一定要留意表间的关联关系

(5)表的查询操作

(1)select distinct/*/列名 from 表名

(2)select 表达式/对列名加别名 from 表名   NULL+X=NULL

(3)where子句,出现在from后面,where是按行筛选

(4)逻辑运算和关系运算

(5)排序:NULL值为最小,使用order by子句,默认升序,order by子句必须放置在最后

(6)复合函数

   ①count()函数,统计之用,不统计NULL值

   ②sum()函数,统计和之用,不要统计非数值,如果统计非数值,返回0

 

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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools