You can specify its own storage path for each partition of the partition table. For the table of the innodb storage engine, you can only specify the data path, because the data and index are stored in a file. The MYISAM storage engine can specify data files and index files separately. Generally, only RANGE, LIST partitions, and sub subpartitions may need to specify the paths of each partition separately. The paths of all partitions of HASH and KEY partitions are the same. The same one. The specified path for the RANGE partition is the same as the LIST partition. Here we will use the LIST partition for explanation. 1. MYISAM storage engine
CREATE TABLE th (id INT, adate DATE) engine='MyISAM'PARTITION BY LIST(YEAR(adate)) ( PARTITION p1999 VALUES IN (1995, 1999, 2003) DATA DIRECTORY = '/data/data' INDEX DIRECTORY = '/data/idx', PARTITION p2000 VALUES IN (1996, 2000, 2004) DATA DIRECTORY = '/data/data' INDEX DIRECTORY = '/data/idx', PARTITION p2001 VALUES IN (1997, 2001, 2005) DATA DIRECTORY = '/data/data' INDEX DIRECTORY = '/data/idx', PARTITION p2002 VALUES IN (1998, 2002, 2006) DATA DIRECTORY = '/data/data' INDEX DIRECTORY = '/data/idx');Note: The data files and index files of the MYISAM storage engine are stored in separate databases, so you can define separate databases for the data files and index files. Path, the INNODB storage engine can only define data paths.
2. INNODB storage engine
CREATE TABLE thex (id INT, adate DATE) engine='InnoDB'PARTITION BY LIST(YEAR(adate)) ( PARTITION p1999 VALUES IN (1995, 1999, 2003) DATA DIRECTORY = '/data/data', PARTITION p2000 VALUES IN (1996, 2000, 2004) DATA DIRECTORY = '/data/data', PARTITION p2001 VALUES IN (1997, 2001, 2005) DATA DIRECTORY = '/data/data', PARTITION p2002 VALUES IN (1998, 2002, 2006) DATA DIRECTORY = '/data/data' );
After specifying the path, innodb generated 4 path files pointing to the data storage in the original path. Myisam generates a th.par file indicating that the table is a partitioned table, and the data files and index files point to the actual storage path.
1. Sub-partition
CREATE TABLE tb_sub_dir (id INT, purchased DATE)
ENGINE='MYISAM'
PARTITION BY RANGE( YEAR(purchased) )
SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
PARTITION p0 VALUES LESS THAN (1990)
(
SUBPARTITION s0
DATA DIRECTORY = '/data/data_sub1'
INDEX DIRECTORY = '/data/idx_sub1',
SUBPARTITION s1
DATA DIRECTORY = '/data/data_sub1'
INDEX DIRECTORY = '/data/idx_sub1'
),
PARTITION p1 VALUES LESS THAN (2000)
(
SUBPARTITION s2
DATA DIRECTORY = '/data/data_sub2'
INDEX DIRECTORY = '/data/idx_sub2',
SUBPARTITION s3
DATA DIRECTORY = '/data/data_sub2'
INDEX DIRECTORY = '/data/idx_sub2'
),
PARTITION p2 VALUES LESS THAN MAXVALUE
(
SUBPARTITION s4
DATA DIRECTORY = '/data/data_sub3'
INDEX DIRECTORY = '/data/idx_sub3',
SUBPARTITION s5
DATA DIRECTORY = '/data/data_sub3'
INDEX DIRECTORY = '/data/idx_sub3'
)
);
CREATE TABLE tb_sub_dirnew (id INT, purchased DATE)
ENGINE='MYISAM'
PARTITION BY RANGE( YEAR(purchased) )
SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
PARTITION p0 VALUES LESS THAN (1990)
DATA DIRECTORY = '/data/data'
INDEX DIRECTORY = '/data/idx'
(
SUBPARTITION s0
DATA DIRECTORY = '/data/data_sub1'
INDEX DIRECTORY = '/data/idx_sub1',
SUBPARTITION s1
DATA DIRECTORY = '/data/data_sub1'
INDEX DIRECTORY = '/data/idx_sub1'
),
PARTITION p1 VALUES LESS THAN (2000)
DATA DIRECTORY = '/data/data'
INDEX DIRECTORY = '/data/idx'
(
SUBPARTITION s2
DATA DIRECTORY = '/data/data_sub2'
INDEX DIRECTORY = '/data/idx_sub2',
SUBPARTITION s3
DATA DIRECTORY = '/data/data_sub2'
INDEX DIRECTORY = '/data/idx_sub2'
),
PARTITION p2 VALUES LESS THAN MAXVALUE
DATA DIRECTORY = '/data/data'
INDEX DIRECTORY = '/data/idx'
(
SUBPARTITION s4
DATA DIRECTORY = '/data/data_sub3'
INDEX DIRECTORY = '/data/idx_sub3',
SUBPARTITION s5
DATA DIRECTORY = '/data/data_sub3'
INDEX DIRECTORY = '/data/idx_sub3'
)
);
Note:
1. The specified path must exist, otherwise the partition cannot be created successfully
2. Data files of the MYISAM storage engine and index files are stored in separate databases, so separate paths can be defined for data files and index files. The INNODB storage engine can only define data paths
The above is the detailed content of Detailed introduction to MySQL specifying the path of each partition. For more information, please follow other related articles on the PHP Chinese website!

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

ToaddauserinMySQL,usetheCREATEUSERstatement.1)UseCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';tocreateauser.2)Enforcestrongpasswordpolicieswithvalidate_passwordpluginsettings.3)GrantspecificprivilegesusingGRANTstatement.4)Forremoteaccess,use

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.


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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

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.
