MySQL中的Rows,Row_format以及MyISAM和InnoDB的一点区别

本文探讨了MySQL中MyISAM和InnoDB两种表类型的特性,重点比较了Rows计数的准确性、Row_format设置及其对存储空间的影响。通过实例说明了不同格式如Dynamic、Fixed和Compressed的特点,并详细解析了InnoDB表的COMPACT和REDUNDANT格式的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前面说到的count(*)的数字MyISAM是存储在一个地方就是表的Rows中,从下面的话中我们可以看出MyISAM存的是一个准确的数字,而InnoDB则存储的是粗略的数字。

Rows

The number of rows in the table. For nontransactional tables, this number is

always accurate. For transactional tables, it is usually an estimate.

 --------------------------------------------------------朴实的分割线----------------------------------------------------------------------------------

Row_format

The row format. For a MyISAM table, this can be Dynamic, Fixed,or Compressed.

Dynamic rows vary in length because they contain variable-length fields such as

VARCHAR or BLOB. Fixed rows, which are always the same size, are made up of

fields that don’t vary in length, such as CHAR and INTEGER. Compressed rows exist

only in compressed tables.

MyISAM是可以修改row_format的,InnoDB测试了一下不行,都是DefaultCOMPACT

下面的内容摘自MySQL官网,解释了COMPACTREDUNDANT的区别。

http://dev.mysql.com/doc/refman/5.1/en/data-size.html

InnoDB tables use a compact storage format. In versions of MySQL earlier than 5.0.3, InnoDB rows contain some redundant information, such as the number of columns and the length of each column, even for fixed-size columns. By default, tables are created in the compact format (ROW_FORMAT=COMPACT). If you wish to downgrade to older versions of MySQL, you can request the old format with ROW_FORMAT=REDUNDANT.

The presence of the compact row format decreases row storage space by about 20% at the cost of increasing CPU use for some operations. If your workload is a typical one that is limited by cache hit rates and disk speed it is likely to be faster. If it is a rare case that is limited by CPU speed, it might be slower.

The compact InnoDB format also changes how CHAR columns containing UTF-8 data are stored. WithROW_FORMAT=REDUNDANT, a UTF-8 CHAR(N) occupies 3 × N bytes, given that the maximum length of a UTF-8 encoded character is three bytes. Many languages can be written primarily using single-byte UTF-8 characters, so a fixed storage length often wastes space. With ROW_FORMAT=COMPACT format, InnoDB allocates a variable amount of storage in the range from N to 3 × N bytes for these columns by stripping trailing spaces if necessary. The minimum storage length is kept as N bytes to facilitate in-place updates in typical cases.

其实REDUNDANT相当于固长,有冗余。COMPACT更灵活,更紧凑。


转自:http://www.cnblogs.com/isql/archive/2009/12/17/Row_format.html

[client] port=3306 [mysql] no-beep default-character-set = utf8mb4 [mysqld] init_connect='SET autocommit=0;' init_file=E:\\MySQL\\init.sql # 基础配置 port=3306 datadir=E:\MySQL\Data default-storage-engine=INNODB server-id=1 lower_case_table_names=1 secure-file-priv="C:/ProgramData/MySQL/MySQL Server 8.2/Uploads" # 修复连接问题的关键设置 bind-address=0.0.0.0 # 允许所有IP连接 skip_name_resolve=ON # 禁用DNS反向解析 # 认证策略修复 authentication_policy=mysql_native_password, # 字符集 character-set-server=utf8mb4 collation-server=utf8mb4_0900_ai_ci # SQL模式 sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION" # 日志配置 log-output=FILE general-log=0 general_log_file="XIANJH.log" slow-query-log=1 slow_query_log_file="XIANJH-slow.log" long_query_time=3 log-error="XIANJH.err" log-bin="XIANJH-bin" binlog_expire_logs_seconds=604800 # 内存优化 max_connections=300 table_open_cache=5000 table_open_cache_instances=16 temptable_max_ram=2G tmp_table_size=512M max_heap_table_size=512M internal_tmp_mem_storage_engine=TempTable # InnoDB优化 innodb_buffer_pool_size=40G innodb_log_file_size=2G innodb_buffer_pool_instances=16 innodb_log_buffer_size=256M innodb_redo_log_capacity=4G innodb_flush_log_at_trx_commit=2 innodb_autoinc_lock_mode=2 bulk_insert_buffer_size=256M innodb_doublewrite=ON innodb_io_capacity=8000 innodb_io_capacity_max=16000 innodb_use_native_aio=ON innodb_flush_method=normal # 线程优化 innodb_thread_concurrency=0 innodb_parallel_read_threads=10 innodb_read_io_threads=10 innodb_write_io_threads=10 thread_cache_size=50 innodb_purge_threads=4 # 连接与网络 max_allowed_packet=256M net_buffer_length=32K max_connect_errors=1000 wait_timeout=300 interactive_timeout=300 # 文件与缓存 open_files_limit=10000 innodb_open_files=5000 innodb_file_per_table=ON innodb_autoextend_increment=128 # 查询优化 join_buffer_size=4M sort_buffer_size=4M read_buffer_size=1M read_rnd_buffer_size=1M # 性能与安全 performance_schema=ON innodb_checksum_algorithm=0 innodb_old_blocks_time=1000 innodb_stats_on_metadata=0 flush_time=0 # 复制相关 binlog_row_event_max_size=8K sync_source_info=10000 sync_relay_log=10000 # MySQL X Protocol loose_mysqlx_port=33060 这是我目前的my.ini的配置,我电脑是WIN10的操作系统,MYSQL版本是8.2,CPU是10核20线程的E5 2666V3,运存是4通道共64G服务器DD3内存,硬盘是SATA协议的1T SSD
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值