Table of Contents
(1)数据类型
(2)mysql小知识
(3)MySQL解决中文乱码(XP下)
(4)表的增删改操作
(5)表的查询操作
Home Database Mysql Tutorial mysql十分全的和完整的总结

mysql十分全的和完整的总结

Jun 07, 2016 pm 04:27 PM
mysql whole Summarize

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 of this Website
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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1667
14
PHP Tutorial
1273
29
C# Tutorial
1255
24
Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

See all articles