MySQL数据文件说明_MySQL
bitsCN.com
MySQL数据文件说明
一.MySQL数据文件说明
先看MySQL DataDirectory下的文件:
这里面dave,mysql 都是我们的数据库名称,我们在进入mysql 数据库查看:
在MySQL 中每一个数据库都会在定义好(或者默认)的数据目录下存在一个以数据库名字命名的文件夹,用来存放该数据库中各种表数据文件。不同的MySQL 存储引擎有各自不同的数据文件,存放位置也有区别。
多数存储引擎的数据文件都存放在和MyISAM 数据文件位置相同的目录下,但是每个数据文件的扩展名却各不一样。如MyISAM 用“.MYD”作为扩展名,Innodb 用“.ibd”,Archive 用“.arc”,CSV 用“.csv”,等等。
1.1 “.ibd”文件和ibdata 文件
这两种文件都是存放Innodb 数据的文件,之所以有两种文件来存放Innodb 的数据(包括索引),是因为Innodb 的数据存储方式能够通过配置来决定是使用共享表空间存放存储数据,还是独享表空间存放存储数据。独享表空间存储方式使用“.ibd”文件来存放数据,且每个表一个“.ibd”文件,文件存放在和MyISAM数据相同的位置。
如果选用共享存储表空间来存放数据,则会使用ibdata 文件来存放,所有表共同使用一个(或者多个,可自行配置)ibdata 文件。ibdata 文件可以通过innodb_data_home_dir 和innodb_data_file_path两个参数共同配置组成, innodb_data_home_dir 配置数据存放的总目录, 而innodb_data_file_path 配置每一个文件的名称。当然,也可以不配innodb_data_home_dir而直接在innodb_data_file_path参数配置的时候使用绝对路径来完成配置。
mysql> showvariables like 'innodb_data%';+-----------------------+------------------------+|Variable_name | Value |+-----------------------+------------------------+|innodb_data_file_path | ibdata1:10M:autoextend || innodb_data_home_dir | |+-----------------------+------------------------+2 rows in set(0.01 sec)
innodb_data_file_path中可以一次配置多个ibdata文件。文件可以是指定大小,也可以是自动扩展的,但是Innodb 限制了仅仅只有最后一个ibdata 文件能够配置成自动扩展类型。当我们需要添加新的ibdata 文件的时候,只能添加在innodb_data_file_path配置的最后,而且必须重启MySQL 才能完成ibdata 的添加工作。
1.2 “.frm”文件
与表相关的元数据(meta)信息都存放在“.frm”文件中,包括表结构的定义信息等。不论是什么存储引擎,每一个表都会有一个以表名命名的“.frm”文件。所有的“.frm”文件都存放在所属数据库的文件夹下面。
1.3 “.MYD”文件
“.MYD”文件是MyISAM 存储引擎专用,存放MyISAM 表的数据。每一个MyISAM 表都会有一个“.MYD”文件与之对应,同样存放于所属数据库的文件夹下,和“.frm”文件在一起。
1.4 “.MYI”文件
“.MYI”文件也是专属于MyISAM存储引擎的,主要存放MyISAM表的索引相关信息。对于MyISAM存储来说,可以被cache 的内容主要就是来源于“.MYI”文件中。每一个MyISAM表对应一个“.MYI”文件,存放于位置和“.frm”以及“.MYD”一样。
小结一下:
MyISAM 存储引擎的表在数据库中,每一个表都被存放为三个以表名命名的物理文件(frm,myd,myi)。 每个表都有且仅有这样三个文件做为MyISAM 存储类型的表的存储,也就是说不管这个表有多少个索引,都是存放在同一个.MYI 文件中。
这个在开始的截图里看的比较清楚。
二.更改MySQL 数据文件目录
MySQL默认的数据文件存储目录为/var/lib/mysql。下面演示一下修改MySQL默认的data directory。
2.1 创建新的目录
[root@rac2 /]# mkdir -p /u01/mysql[root@rac2 lib]# chown mysql.mysql/u01/mysql[root@rac2 lib]# chmod -R 777 /u01/mysql
2.2 停mysql
[root@rac2 lib]# service mysql stopShutting down MySQL... [ OK ][root@rac2 lib]# ps -ef|grep mysqlroot 3955 3799 0 20:00 pts/2 00:00:00 grep mysql
2.3 移动目录
[root@rac2 lib]# mv /var/lib/mysql /u01/
2.4 修改my.cnf配置文件
如果/etc/目录下没有my.cnf配置文件,到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf。命令如下:
[root@rac2 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
vi修改my.cnf的sock 文件位置:
# The MySQL server
[mysqld]port = 3306#socket = /var/lib/mysql/mysql.socksocket = /u01/mysql/mysql.sockskip-external-lockingkey_buffer_size = 16M#max_allowed_packet = 1Mmax_allowed_packet=100Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M
2.5 修改启动脚本:
/etc/init.d/myql[root@rac2 mysql]# vi /etc/init.d/mysqldatadir=/u01/mysql
2.6 启动mysql
[root@rac2 mysql]# service mysql startStarting MySQL..... [ OK ]
启动成功,查看进程:
[root@rac2 mysql]# ps -ef|grep mysqlroot 11512 1 2 21:02 pts/2 00:00:00 /bin/sh /usr/bin/mysqld_safe--datadir=/u01/mysql --pid-file=/u01/mysql/rac2.pidmysql 11769 11512 5 21:02 pts/2 00:00:00 /usr/sbin/mysqld --basedir=/usr--datadir=/u01/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql--log-error=/u01/mysql/rac2.err --pid-file=/u01/mysql/rac2.pid--socket=/u01/mysql/mysql.sock --port=3306root 11796 3799 0 21:02 pts/2 00:00:00 grep mysql
2.7 其中的小插曲:
之前给/u01/mysql 目录赋的755 权限,但是启动报错:
[root@rac2 mysql]# service mysql startStarting MySQL....The server quit withoutupdating PID file[FAILED]ysql/rac2.pid).
查看log:
/u01/mysql/rac2.err111130 20:59:34 [Note] /usr/sbin/mysqld:Shutdown complete111130 20:59:34 mysqld_safe mysqld from pidfile /u01/mysql/rac2.pid ended111130 21:02:25 mysqld_safe Starting mysqlddaemon with databases from /u01/mysql/usr/sbin/mysqld: File './mysql-bin.~rec~'not found (Errcode: 13)111130 21:02:25 [ERROR]MYSQL_BIN_LOG::open_purge_index_file failed to open register file.111130 21:02:25 [ERROR]MYSQL_BIN_LOG::open_index_file failed to sync the index file.111130 21:02:25 [ERROR] Aborting
应该是权限不够,不能创建pid 文件,赋给777 权限后,正常:
chmod -R 777 /u01/mysql[root@rac2 mysql]# ll /u01/mysql/rac2.pid-rw-rw---- 1 mysql mysql 6 Nov 30 21:02/u01/mysql/rac2.pid
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











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...
