mysql分区管理-range分区_MySQL
bitsCN.com
为了更好的演示range分区,首先对mysql server的启动和关闭进行说明: 一,如何启动mysqld? 本人把mysql安装在windows环境下,安装的主目录homedir是"c:/Program Files
/MySQL/MySQL Server 5.1/",启动方法非常简单:首先进入cmd命令行窗口,如下图: 执行如下命令:cd c:/Program Files/MySQL/MySQL Server 5.1/,进入mysql安装目录,
可以看到bin目录,该目录是存放mysql的各种可执行文件,cd bin,进入该目录, 找到mysqld.exe的可执行文件,执行mysqld,即启动mysqld,如下图:
此时,打开任务管理器 - 》进程,可以看到mysqld.exe,表示启动成功。 二,如何关闭mysqld? 运行cmd,将路径切换到:c:/Program Files/MySQL/MySQL Server 5.1/bin下,用命令 mysqladmin -u root -p shutdown 如下图所示:
三,innodb_file_per_table设置 mysql innodb 存储引擎对表空间的管理在默认情况下是使用共享表空间,
即所有表的索引和数据均放在一个以ibdata1的文件中,我们可以执行下面的命令查看: 可以看到对应的Value: OFF,下面我们在配置文件my.ini增加下面一行: #tenfy: 新添加的参数 innodb_file_per_table=1 然后,重新启动mysqld,此时,可以看到:
那么,你也许会问,之前在innodb_file_per_table=0的时候已经创建的表,
此时还是继续使用共享表空间吗?是的,如果我们不对表进行修改,之前的可以继续使用,但 将共享表空间修改成独立表空间,除了修改innodb_file_per_table参数外,
我们需要修改所有innodb的表都运行如下: alter table table_name engine=innodb; (tenfy:注意红色部分必须添加,
否则无法生效),一旦执行完成后,我们可以在data的mytest1目录下,看到根据各个分区
生成的各个.ibd后缀的文件,这些文件就是独立表空间文件,每个分区对应一个。
(关于分区我们将在下面讲解)
四,mysql分区概述 分区功能并不是在存储引擎层完成的,因此除了innodb支持分区外,MyISAM,NDB
等均支持分区功能,而CSV,FEDERATED,MERGE则不支持分区功能。而MySQL在5.1版本时
添加了对分区功能的支持。 分区是将一个表或者索引物分解成多个更小的,更可管理的部分,而对用户访问db的应用来说,
从逻辑上看,只有一个表或者一个索引(这里跟分库分表的访问不一样),但在物理上这个表或者
索引可能是由许多个物理分区组成的,每个分区都是一个独立的对象,可以进行独立处理。 那么怎么判断当前数据库是否启用了分区功能呢?可以执行如下命令进行查看: 或者:
当前MySQL支持以下几种分区: 1,RANGE分区:顾名思义,区间分区,行数据基于一个给定连续区间的列值放入分区。 2,LIST分区:列表分区,与RANGE分区类似,只是LIST分区面向的是离散可列举的值。 3,HASH分区:根据用户自定义的表达式的返回值来进行分区,返回值不能是负数。 4,KEY分区:根据MySQL数据库提供的哈希函数进行分区。 但是不论什么类型的分区,必须注意以下两个问题: 1,如果表中存在primary key 或者unique key时,分区的列必须是primary key或者
unique key的一个组成部分,也就是说,分区函数的列只能从pk或者uk这些key中取子集。 如下: 表par_tb1有唯一key,他们对应的列是col1,col2。而此时进行分区的列却是col3,
因此出现1503错误,此时我们把col3加入到unique key或者用col1或者col2进行分区均 没问题: 2,如果表中不存在任何的primary key或者unique key,则可以指定任何一个列作为分区列。 五,RANGE分区。 RANGE分区是最常用的一种分区类型,它的特点主要是按照某个列连续的值进行分区,
因此在分区中常常使用values less than (xxx),下面我们以具体的例子来说明。 首先我们创建一个表,名字叫:range_par_tbl,有一个int类型的id字段,当id小于10的
时候,插入第一个分区,当id小于20的时候插入第二分区。如下: 此时,我们查看对应的分区表空间文件(注意:因为我们之前设置了innodb_file_per_table=1),
此时启用分区后,表已经由建立分区时的各个分区ibd文件组成了,由于我们分了两个区,
因此可以看到对应的两个文件:
可以看到,分区对应的表空间文件命名规则为:表名

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 is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting
