Table of Contents
数据目录的位置
数据库在文件系统的表示方法
表在文件系统的表示方式
视图和触发器在文件系统的表示方式
存储过程和函数在文件系统的表示方法
Home Database Mysql Tutorial [MySQL] 数据目录的机关架构

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

Jun 07, 2016 pm 04:15 PM
mysql data organ Architecture Table 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
Copy after login
其中的--datadir指定的就是数据目录的位置。 2)查看my.cnf的配置信息:
[mysqld]
datadir = /data/mysql/data
Copy after login
3)登陆数据库,运行show variables命令查看:
mysql> show variables like 'datadir';
+---------------+-------------------+
| Variable_name | Value             |
+---------------+-------------------+
| datadir       | /data/mysql/data/ | 
+---------------+-------------------+
1 row in set (0.00 sec)
Copy after login

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

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
Copy after login

表在文件系统的表示方式

因为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
Copy after login
根据上面的配置,将在数据目录下创建两个文件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
Copy after login

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months 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)

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

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.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

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 a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

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.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

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.

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

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.

How steep is the learning curve of golang framework architecture? How steep is the learning curve of golang framework architecture? Jun 05, 2024 pm 06:59 PM

The learning curve of the Go framework architecture depends on familiarity with the Go language and back-end development and the complexity of the chosen framework: a good understanding of the basics of the Go language. It helps to have backend development experience. Frameworks that differ in complexity lead to differences in learning curves.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

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

70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI 70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI Jun 13, 2024 pm 03:47 PM

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

See all articles