Table of Contents
1 事务的特性
2 MySQL存储引擎
3 选择合适的MySQL存储引擎
4 MySQL特点
5 MySQL支持的数据类型
6 MySQL内置函数
7 MySQL解决乱码问题
Home Database Mysql Tutorial 面试-MySQL_MySQL

面试-MySQL_MySQL

Jun 01, 2016 pm 12:59 PM

 

1 事务的特性

 

事务具有四个特性:原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持续性(Durability)。这四个特性也简称ACID性。

(1)原子性:事务是应用中最小的执行单位,就如原子是自然界最小颗粒,具有不可再分的特征一样。事务是应用中不可再分的最小逻辑执行体。

(2)一致性:事务执行的结果,必须使数据库从一个一致性状态,变到另一个一致性状态。当数据库中只包含事务成功提交的结果时,数据库处于一致性状态。一致性是通过原子性来保证的。

(3)隔离性:各个事务的执行互不干扰,任意一个事务的内部操作对其他并发的事务,都是隔离的。也就是说:并发执行的事务之间不能看到对方的中间状态,并发执行的事务之间不能相互影响。

(4)持久性:指事务一旦提交,对数据所做的任何改变,都要记录到永久存储器中,通常是保存进物理数据库。

2 MySQL存储引擎

 

特点

Myisam

BDB

Memory

InnoDB

Archive

存储限制

没有

没有

64TB

没有

事务安全

 

支持

 

支持

 

锁机制

表锁

页锁

表锁

行锁

行锁

B树索引

支持

支持

支持

支持

 

哈希索引

   

支持

支持

 

全文索引

支持

       

集群索引

     

支持

 

数据缓存

   

支持

支持

 

索引缓存

支持

 

支持

支持

 

数据可压缩

支持

     

支持

空间使用

N/A

非常低

内存使用

中等

批量插入的速度

非常高

支持外键

     

支持

 


Myisam:每个MyISAM在磁盘上存储成三个文件。文件名都和表名相同,扩展名分别是.frm(存储表定义)、.MYD(MYData,存储数据)、.MYI(MYIndex,存储索引)。数据文件和索引文件可以放置在不同的目录,平均分布io,获得更快的速度。最常使用的2种存储引擎:

 

InnoDB:是Mysql的默认存储引擎。当create创建新表时,未指定新表的存储引擎时,默认使用InnoDB。存储引擎提供了具有提交、回滚和崩溃恢复能力的事务安全。但是对比Myisam的存储引擎,InnoDB写的处理效率差一些并且会占用更多的磁盘空间以保留数据和索引。

3 选择合适的MySQL存储引擎

选择标准:根据应用特点选择合适的存储引擎,对于复杂的应用系统可以根据实际情况选择多种存储引擎进行组合。下面是常用存储引擎的适用环境:

MyISAM:在Web、数据仓储和其他应用环境下最常使用的存储引擎之一。

InnoDB:默认的MySQL插件式存储引擎,用于事务处理应用程序,具有众多特性,包括ACID事务支持。

Memory:将所有数据保存在RAM中,在需要快速查找引用和其他类似数据的环境下,可提供极快的访问。

Merge:允许MySQLDBA或开发人员将一系列等同的MyISAM表以逻辑方式组合在一起,并作为1个对象引用它们。对于诸如数据仓储等VLDB环境十分适合。

4 MySQL特点

与其他数据库Oracle、DB2、SQL Server等相比功能稍弱一些

1、可以处理拥有上千万条记录的大型数据;

2、支持常见的SQL语句规范 ;

3、可移植行高,安装简单小巧 ;

4、良好的运行效率,有丰富信息的网络支持;

5、调试、管理,优化简单(相对其他大型数据库)。

5 MySQL支持的数据类型

数值型:

\

 

日期时间类型:

\

 

字符串类型:

\

 

空间数据类型:

\

 

6 MySQL内置函数

数学函数

BIN(x):返回x的二进制(OCT返回八进制,HEX返回十六进制)

FLOOR(x):返回小于x的最大整数值

ROUND(x,y):返回参数x的四舍五入的有y位小数的值

LOG(x,y):返回x的以y为底的对数

MOD(x,y):返回x/y的模(余数)

聚合函数:

COUNT(col):返回指定列中非NULL值的个数

MIN(col):返回指定列的最小值

MAX(col):返回指定列的最大值

SUM(col):返回指定列的所有值之和

字符串函数:

LENGTH(s):返回字符串str中的字符数

CONCAT(s1,s2...,sn):将s1,s2...,sn连接成字符串

TRIM(str):去除字符串首部和尾部的所有空格

LEFT(str,x):返回字符串str中最左边的x个字符

RIGHT(str,x):返回字符串str中最右边的x个字符

日期时间函数:

NOW():返回当前的日期和时间

WEEK(date):返回日期date为一年中第几周(0~53)

YEAR(date):返回日期date的年份(1000~9999)

DAYOFWEEK(date):返回date所代表的一星期中的第几天(1~7)

DAYOFMONTH(date):返回date是一个月的第几天(1~31)

DAYOFYEAR(date):返回date是一年的第几天(1~366)

加密函数:

MD5():计算字符串str的MD5校验和

ENCRYPT(str,salt):使用UNIXcrypt()函数,用关键词salt(一个可以惟一确定口令的字符串,就像钥匙一样)加密字符串str

控制流函数:MySQL有4个函数是用来进行条件操作的,这些函数可以实现SQL的条件逻辑,允许开发者将一些应用程序业务逻辑转换到数据库后台。

SELECT CASE 'green'

WHEN 'red' THEN 'stop'

WHEN 'green' THEN 'go' END;

格式化函数:

DATE_FORMAT(date,fmt):依照字符串fmt格式化日期date值

TIME_FORMAT(time,fmt):依照字符串fmt格式化时间time值

类型转化函数:

为了进行数据类型转化,MySQL提供了CAST()函数,它可以把一个值转化为指定的数据类型。类型有:BINARY,CHAR,DATE,TIME,DATETIME,SIGNED,UNSIGNED

示例:

SELECT CAST(NOW() AS SIGNED INTEGER), CURDATE()+0;

SELECT 'f'=BINARY 'F', 'f'=CAST('F' AS BINARY);

系统信息函数:

CONNECTION_ID():返回当前客户的连接ID

VERSION():返回MySQL服务器的版本

USER()或SYSTEM_USER():返回当前登陆用户名

FOUND_ROWS():返回最后一个SELECT查询进行检索的总行数

http://bxbx258.blog.bitsCN.com/339450/106008

7 MySQL解决乱码问题

在数据库安的时候指定字符集,如果在安完了以后可以更改以下文件:C:\ProgramFiles\MySQL\MySQL Server 5.0\my.ini 里的所有的 default-character-set=gbk C:\Program Files\MySQL\MySQL Server 5.0\data\depot_development\db.optdefault-character-set=gbk default-collation=gbk_chinese_ci 建立数据库时候:指定字符集类型
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 尊渡假赌尊渡假赌尊渡假赌

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
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

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.

How does MySQL index cardinality affect query performance? How does MySQL index cardinality affect query performance? Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: From Small Businesses to Large Enterprises MySQL: From Small Businesses to Large Enterprises Apr 13, 2025 am 12:17 AM

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

See all articles