mysql十分全的和完整的总结
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

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
