MySQL发行版的选择

MySQL官方发行版

MySQL是最流行的数据库,主要特点:

  • 简单:MySQL使用很简单,任何稍微有IT背景的技术人员都可以无师自通地参照文档安装运行和使用MySQL,这几乎没有什么门槛。
  • 开源:开源意味着流行和免费。
  • 支持多种存储引擎:MySQL有多种存储引擎,每种存储引擎有各自的优缺点,可以择优选择使用:MyISAM、InnoDB、MERGE、MEMORY(HEAP)、BDB(BerkeleyDB)、EXAMPLE、FEDERATED、ARCHIVE、CSV、BLACKHOLE。
  • 支持高可用架构:MySQL自身提供的replication(主从复制)功能可以实现MySQL数据的实时备份。

Mysql与存储引擎

Mysql最常用的有两个存储引擎:MyISAMInnoDB

MySQL4和5使用默认的MyISAM存储引擎。从MYSQL5.5开始,MySQL已将默认存储引擎从MyISAM更改为InnoDB。

两种存储引擎的大致区别表现在:

  1. InnoDB支持事务,MyISAM不支持,这一点是非常之重要。事务是一种高级的处理方式,如在一些列增删改中出错还可以回滚还原,而MyISAM就不可以了。
  2. MyISAM查询数据相对较快,适合大量的select ,可以全文索引,InnoDB适合频繁修改以及涉及到安全性较高的应用.
  3. InnoDB支持外键,支持行级锁,MyISAM不支持
  4. MyISAM索引和数据是分开的,而且其索引是压缩的,缓存在内存的是索引,不是数据。而InnoDB缓存在内存的是数据,相对来说,服务器内存越大,InnoDB发挥的优势越大。
  5. InnoDB可支持大并发请求,适合大量insert、update操作。

关于MyISAM与InnoDB选择使用

  1. 如果应用程序一定要使用事务,毫无疑问要选择INNODB引擎。
  2. 如果应用程序对查询性能要求较高,就要使用MYISAM了。MYISAM拥有全文索引的功能,这可以极大地优化查询的效率。

查看数据库引擎

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

查看表的引擎

--查看mysql数据库的user表
mysql> show table status from mysql where name='user';
+------+--------+---------...+-----------------------------+
| Name | Engine | Version ...| Comment                     |
+------+--------+---------...+-----------------------------+
| user | MyISAM |      10 ...| Users and global privileges |
+------+--------+---------...+-----------------------------+
1 row in set (0.00 sec)

--或者如果太长,可以竖着显示
mysql> show table status from mysql where name='user' \G
*************************** 1. row ***************************
           Name: user
         Engine: MyISAM
        Version: 10
     Row_format: Dynamic
           Rows: 4
 Avg_row_length: 114
    Data_length: 456
Max_data_length: 281474976710655
   Index_length: 4096
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2022-04-30 23:58:46
    Update_time: 2022-05-01 00:25:02
     Check_time: NULL
      Collation: utf8_bin
       Checksum: NULL
 Create_options: 
        Comment: Users and global privileges
1 row in set (0.00 sec)

不同存储引擎的文件结构

InnoDB引擎

mysql> show table status from mysql where name='time_zone_name' \G
*************************** 1. row ***************************
           Name: time_zone_name
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 0
 Avg_row_length: 0
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2022-04-30 23:58:46
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: stats_persistent=0
        Comment: Time zone names
1 row in set (0.00 sec)
#由以.frm结尾的文件存储数据结构
$ ll /data/mysql/mysql/ | grep time_zone_name
-rw-r----- 1 mysql mysql    8606 4月  30 23:58 time_zone_name.frm
#由ibdata1文件存储实际数据
$ ll /data/mysql/ | grep data
-rw-r----- 1 mysql mysql   12582912 5月   1 01:02 ibdata1

MyISAM引擎

mysql> show table status from mysql where name='user' \G
*************************** 1. row ***************************
           Name: user
         Engine: MyISAM
        Version: 10
     Row_format: Dynamic
           Rows: 4
 Avg_row_length: 114
    Data_length: 456
Max_data_length: 281474976710655
   Index_length: 4096
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2022-04-30 23:58:46
    Update_time: 2022-05-01 00:25:02
     Check_time: NULL
      Collation: utf8_bin
       Checksum: NULL
 Create_options: 
        Comment: Users and global privileges
1 row in set (0.00 sec)
ll /data/mysql/mysql/ | grep user
-rw-r----- 1 mysql mysql   10816 4月  30 23:58 user.frm  #由以.frm结尾的文件存储数据结构
-rw-r----- 1 mysql mysql     456 5月   1 00:25 user.MYD  #由以.MYD结尾的文件存储数据
-rw-r----- 1 mysql mysql    4096 5月   1 00:56 user.MYI  #由以.MYI结尾的文件存储索引

Percona Server分支

Percona Server由领先的MySQL咨询公司Percona发布。

Percona Server是一款独立的数据库产品,其可以完全与MySQL兼容,可以在不更改代码的情况了下将存储引擎更换成XtraDB。是最接近官方MySQL Enterprise发行版的版本。

Percona提供了高性能XtraDB引擎,还提供PXC高可用解决方案,并且附带了percona-toolkit等DBA管理工具箱。

MariaDB

MariaDB由MySQL的创始人开发,MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

MariaDB提供了MySQL提供的标准存储引擎,即MyISAM和InnoDB,10.0.9版起使用XtraDB(名称代号为Aria)来代替MySQL的InnoDB。

如何选择

综合多年使用经验和性能对比,线上业务系统首选Percona分支,其次是MYSQL版本,最后是MariaDB。

各发行版本的下载地址

mysql

https://downloads.mysql.com/archives/community/

percona

下载对标mysql的

https://www.percona.com/downloads/Percona-Server-5.7/LATEST/

mariadb

https://mariadb.org/download/

或者

https://mariadb.com/downloads/

或者

https://downloads.mariadb.com/MariaDB/

posted @ 2022-12-18 21:41  厚礼蝎  阅读(59)  评论(0编辑  收藏  举报