search
HomeDatabaseMysql Tutorial[MySQL] 数据目录的机关架构

[MySQL] 数据目录的机关架构

Jun 07, 2016 pm 04:15 PM
mysqldataorganArchitectureTable of contents

[MySQL] 数据目录的组织架构 归根到底,MySQL是运行在操作系统上的一个软件,它需要借助于文件系统存储数据,本文主要介绍MySQL数据目录的组织架构。 数据目录的位置 可以通过以下几个方法查看MySQL数据目录的位置:1)对于一个正在运行的MySQL服务器来说,可

[MySQL] 数据目录的组织架构
归根到底,MySQL是运行在操作系统上的一个软件,它需要借助于文件系统存储数据,本文主要介绍MySQL数据目录的组织架构。

数据目录的位置

可以通过以下几个方法查看MySQL数据目录的位置: 1)对于一个正在运行的MySQL服务器来说,可以通过查看mysqld的进程获取MySQL数据目录的位置,如下所示:
[root@lx202 /data/mysql/data ]# ps -ef|grep mysqld
root      5841  7337  0 15:09 pts/1    00:00:00 grep --color=auto mysqld
root     27034     1  0  2012 ?        00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/data/lx202.pid
mysql    27889 27034 30  2012 ?        111-03:03:55 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/data/mysql/data --plugin-dir=/opt/mysql/lib/mysql/plugin --user=mysql --log-error=/data/mysql/log/alert.log --open-files-limit=65535 --pid-file=/data/mysql/data/lx202.pid --socket=/opt/mysql/run/mysql.sock --port=3306
其中的--datadir指定的就是数据目录的位置。 2)查看my.cnf的配置信息:
[mysqld]
datadir = /data/mysql/data
3)登陆数据库,运行show variables命令查看:
mysql> show variables like 'datadir';
+---------------+-------------------+
| Variable_name | Value             |
+---------------+-------------------+
| datadir       | /data/mysql/data/ | 
+---------------+-------------------+
1 row in set (0.00 sec)

数据库在文件系统的表示方法

MySQL里,每个数据库都对应一个数据目录里的一个字目录,当你用create database db_name语句创建一个数据库时,将在数据目录下创建一个同名的子目录,在该子目录下,有一个db.opt文件,用于记录数据库默认的字符集和排序方式,如下所示:
[root@lx202 /data/mysql/data/portal ]# cat db.opt
default-character-set=utf8
default-collation=utf8_general_ci

表在文件系统的表示方式

因为MySQL支持多个存储引擎,所以表在文件系统的表示方式根据存储引擎的不同而不同。但无论哪种存储引擎,每个表至少对应一个同名的.frm文件,该文件用于描述表结构信息。除了.frm文件之外,各个存储引擎用于存储数据的文件各不相同,下面我们介绍几种常见的存储引擎:
MyISAM - table_name.MYD:数据文件 - table_name.MYI:索引文件 MERGE - table_name.MRG:文本文件 InnoDB InnoDB表的存储是基于表空间的,有两种类型的表空间: 1)共享表空间:由数据目录里的一个或多个大文件构成,这些文件共同组成了一个在逻辑上连续不断的存储区域,共享表空间是通过参数innodb_data_file_path设置的,如下所示:
innodb_data_file_path = ibdata1:10G;ibdata2:5G:autoextend
根据上面的配置,将在数据目录下创建两个文件ibdata1和ibdata2来存放innodb的数据。 2)独占表空间:当设置innodb_file_per_table = 1后,每个表对对应一个单独使用的表空间文件.ibd(在其对应的数据库目录下) 这里需要注意的是:即使你配置了独占表空间,共享表空间也是需要的,因为InnoDB的数据字典必须存放在共享表空间里。

视图和触发器在文件系统的表示方式

每个视图包含一个.frm文件,它包含该视图的定义和属性等。 触发器保存在一个.TRG文件里,里面包含着它的定义和属性,但文件不是以触发器命名,而是以触发器相关联的表命名。

存储过程和函数在文件系统的表示方法

MySQL的存储过程和函数分别存放在mysql数据库目录的proc*和func*文件里,如:
[root@lx202 /data/mysql/data/mysql ]# ls proc*
proc.frm  proc.MYD  proc.MYI  procs_priv.frm  procs_priv.MYD  procs_priv.MYI
[root@lx202 /data/mysql/data/mysql ]# ls func*
func.frm  func.MYD  func.MYI

Statement
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
What are the differences in syntax between MySQL and other SQL dialects?What are the differences in syntax between MySQL and other SQL dialects?Apr 27, 2025 am 12:26 AM

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

What is MySQL partitioning?What is MySQL partitioning?Apr 27, 2025 am 12:23 AM

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How do you grant and revoke privileges in MySQL?How do you grant and revoke privileges in MySQL?Apr 27, 2025 am 12:21 AM

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.

Explain the differences between InnoDB and MyISAM storage engines.Explain the differences between InnoDB and MyISAM storage engines.Apr 27, 2025 am 12:20 AM

InnoDB is suitable for applications that require transaction support and high concurrency, while MyISAM is suitable for applications that require more reads and less writes. 1.InnoDB supports transaction and bank-level locks, suitable for e-commerce and banking systems. 2.MyISAM provides fast read and indexing, suitable for blogging and content management systems.

What are the different types of JOINs in MySQL?What are the different types of JOINs in MySQL?Apr 27, 2025 am 12:13 AM

There are four main JOIN types in MySQL: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN returns all rows in the two tables that meet the JOIN conditions. 2.LEFTJOIN returns all rows in the left table, even if there are no matching rows in the right table. 3. RIGHTJOIN is contrary to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet JOIN conditions.

What are the different storage engines available in MySQL?What are the different storage engines available in MySQL?Apr 26, 2025 am 12:27 AM

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

What are some common security vulnerabilities in MySQL?What are some common security vulnerabilities in MySQL?Apr 26, 2025 am 12:27 AM

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

How can you identify slow queries in MySQL?How can you identify slow queries in MySQL?Apr 26, 2025 am 12:15 AM

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.

See all articles

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 Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function