[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/data3)登陆数据库,运行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

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

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 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.

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.

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.

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

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.

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*.


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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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
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
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
Small size, syntax highlighting, does not support code prompt function
