[MySQL]数据目录的组织架构_MySQL
bitsCN.com
[MySQL]数据目录的组织架构
归根到底,MySQL是运行在操作系统上的一个软件,它需要借助于文件系统存储数据,本文主要介绍MySQL数据目录的组织架构。
数据目录的位置
可以通过以下几个方法查看MySQL数据目录的位置:
1)对于一个正在运行的MySQL服务器来说,可以通过查看mysqld的进程获取MySQL数据目录的位置,如下所示:
[plain][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的配置信息:
[plain] [mysqld] datadir = /data/mysql/data
3)登陆数据库,运行show variables命令查看:
[sql] 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文件,用于记录数据库默认的字符集和排序方式,如下所示:
[plain] [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设置的,如下所示:
[plain] 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*文件里,如:
[plain] [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
bitsCN.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Zookeeper performance tuning on CentOS can start from multiple aspects, including hardware configuration, operating system optimization, configuration parameter adjustment, monitoring and maintenance, etc. Here are some specific tuning methods: SSD is recommended for hardware configuration: Since Zookeeper's data is written to disk, it is highly recommended to use SSD to improve I/O performance. Enough memory: Allocate enough memory resources to Zookeeper to avoid frequent disk read and write. Multi-core CPU: Use multi-core CPU to ensure that Zookeeper can process it in parallel.

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

When installing PyTorch on CentOS system, you need to carefully select the appropriate version and consider the following key factors: 1. System environment compatibility: Operating system: It is recommended to use CentOS7 or higher. CUDA and cuDNN:PyTorch version and CUDA version are closely related. For example, PyTorch1.9.0 requires CUDA11.1, while PyTorch2.0.1 requires CUDA11.3. The cuDNN version must also match the CUDA version. Before selecting the PyTorch version, be sure to confirm that compatible CUDA and cuDNN versions have been installed. Python version: PyTorch official branch

Yes, VS Code supports file comparison, providing multiple methods, including using context menus, shortcut keys, and support for advanced operations such as comparing different branches or remote files.
