search
HomeDatabaseMysql TutorialMySQL中文参考手册---MySQL 文件系统_MySQL

MySQL中文参考手册---MySQL 文件系统_MySQL

Jun 01, 2016 pm 02:12 PM
sqlChineseusemanualnumberdocumentTable of contentssystem

手册


  这是一款正在开发中的Linux 文件系统,能把Linux 上的 MySQL 数据库作为文件系统来处理。开发小组希望能得到 更多的建议,下面的文章翻译自:
  
  实际上,这不是通常意义上的文件系统,它没有磁盘空间, 而是使用MySQL 守护程序来存储数据。可以把SQL 表和 一些函数通过文件系统来实现。
  
  一、怎样实现?
  让我们来看使用实例:
  
  [root@localhost /root]# mount -t corbafs -o `cat /tmp/mysqlcorbafs.ior` none
  /mnt/mysql/
  
  [root@localhost /root]# mount
  /dev/hda3 on / type ext2 (rw)
  none on /proc type proc (rw)
  none on /dev/pts type devpts (rw,gid=5,mode=620)
  /dev/hda1 on /mnt/win type vfat (rw,mode=777)
  /dev/hda4 on /mnt/linux type vfat (rw,noexec,nosuid,nodev,mode=777)
  none on /mnt/mysql type corbafs
  (rw,IOR:01e50d401b00000049444c3a436f72626146532f46696c6553797374656d3a312e
  300000010000000000000030000000010100000a0000003132372e302e302e310008041800
  0000000000009224bc335663462a01000000ef7ae13c0943c59f)
  
  [root@localhost /root]# ls -la /mnt/mysql/
  
  total 0
  
  -r-xr-xr-x 1 root root 4096 dets 29 22:21 .uptime
  dr-xr-xr-x 1 root root 4096 dets 29 22:21 test
  dr-xr-xr-x 1 root root 4096 dets 29 22:21 mysql
  
  [root@localhost /root]# cat /mnt/mysql/.uptime
  
  1994
  
  [root@localhost /root]# cat /mnt/mysql/mysql/user/Host
  
  cpq.spam.ee
  cpq.spam.ee
  localhost
  localhost
  localhost
  localhost
  localhost
  localhost
  
  [root@localhost /root]# cat /mnt/mysql/mysql/user/Insert_priv
  N
  N
  N
  N
  N
  N
  Y
  Y
  
  [root@localhost /root]# umount /mnt/mysql/
  
  二、为什么要这样做呢?
  在一些情形下,这样做能让工作更加轻松。MySQL 和文件系统都能叫做数据库,但是有 着绝然不同的概念和优缺点。在文件系统里,对象能很快而且很容易找到,即使改变名 字也能很快找到。每一个初学者大概都应该学会move/copy/rename/delete这样的操作。 但是SQL 不一样, 他通过应用程序来操纵存储在文件系统上的数据。而MySQL 文件系统把SQL 做到了用户 级。用户能用他们知道的方式来操作数据库。
  
  -任何一个新产品需要通过网络存取数据的话,必须支持一些协议以及可能的其他办法通 过网络存取文件系统。MySQL 表就可以通过这样的方式来存取,即使MySQL 没有移植到 对应的平台。
  
  -备份和版本控制,普通的文件系统通过任何备份软件就可以实现。数据可以通过diff 来比较并且用cvs 来控制版本。
  
  -更短的编程时间,有时候人们需要保存简单的数据,像当前日期或者站点名字,这些数 据很少改变,普通的方法需要使用:
  
  连接服务器-> 选择数据库 -> 执行命令-> 存储结果
  
  而使用 MySQL 文件系统后,只需要一句话:(PHP实现)
  
  include(¨/mountpoint/database/table/field¨);
  
  或者,换一种方式表达:
  
  include(¨/mnt/mysql/sitedata/topic/todaytopic¨);
  
  这样就很容易理解,也占用了较少的空间。还可以通过SAMBA 来共享 /mnt/mysql,达到 直接修改SQL 数据库 的目的。能直接写文本到数据库,或者使用拷贝/粘贴功能把图片放入数据库,这要比用 Perl 或者PHP 写几百行程序省力多了。
  
  三、性能如何?
  在发表这篇文章的时候,这个文件系统还处于原型开发阶段,因此,速度还不是很理想。 如果到了正式发布的时候,一些数据库功能会比使用 SQL 要快。 当然,很多还是没法和 SQL 相比,无论是性能上还是功能上,很多复杂的查询依然需要通过SQL 语句来完成。但 是,这样节省了很多开发和培训的时间,所以在效率上来说也是一种节省。
  
  四、支持的表类型:
  目前这个文件系统支持所有的表类型:MyISAM,DBD,HEAP,ISAM。
  
  五、其他的特色:
  在第一步开发中实现的还只是只读,很快会有能读写的版本出来。目前的计划是把数据库 对象映射成文件和目录对象。让我们来看看例子:
  
  --8  #建立表
  
  CREATE TABLE invoice (
  invoice_id int(10) unsigned NOT NULL auto_increment,
  invoice_no int(10) unsigned DEFAULT '0' NOT NULL,
  payee char(40) DEFAULT '' NOT NULL,
  PRIMARY KEY (invoice_id),
  KEY payee (payee)
  );
  
  # 插入数据
  
  INSERT INTO invoice VALUES (1,100,'Company AB');
  INSERT INTO invoice VALUES (2,101,'Company CD');
  INSERT INTO invoice VALUES (3,102,'Company EF');
  
  --8  
  因为 MySQL 没有办法使用记录号,所以我们必须建立主键。 就有了以下的目录结构:
  
  /mountpoint/database/table/primary_key/field
  
  这样,每个列出现在不同的文件行之中,文件树的结构如下:
  
  /mnt/mysql/mydata/invoice/1/invoice_id
  /mnt/mysql/mydata/invoice/1/invoice_no
  /mnt/mysql/mydata/invoice/1/payee
  /mnt/mysql/mydata/invoice/2/invoice_id
  /mnt/mysql/mydata/invoice/2/invoice_no
  /mnt/mysql/mydata/invoice/2/payee
  /mnt/mysql/mydata/invoice/3/invoice_id
  /mnt/mysql/mydata/invoice/3/invoice_no
  /mnt/mysql/mydata/invoice/3/payee
  
  另外,还有第二个办法可以使用:
  
  /mountpoint/database/table/.table
  和
  /mountpoint/database/table/primary_key/.record
  /mnt/mysql/mydata/invoice/.table
  /mnt/mysql/mydata/invoice/1/.record
  /mnt/mysql/mydata/invoice/1/invoice_id
  /mnt/mysql/mydata/invoice/1/invoice_no
  /mnt/mysql/mydata/invoice/1/payee
  /mnt/mysql/mydata/invoice/2/.record
  /mnt/mysql/mydata/invoice/2/invoice_id
  /mnt/mysql/mydata/invoice/2/invoice_no
  /mnt/mysql/mydata/invoice/2/payee
  /mnt/mysql/mydata/invoice/3/.record
  /mnt/mysql/mydata/invoice/3/invoice_id
  /mnt/mysql/mydata/invoice/3/invoice_no
  /mnt/mysql/mydata/invoice/3/payee
  
  这些文件是隐含的,以防重复,主要用来方便地通过文本文件浏览器来查看。
  
  现在,在那些需要使用SQL 语句搜索最小,最大,最后等数据,可以通过符号连接来实
  现了:
  
  /mountpoint/database/table/primary_key/.max
  或者
  /mnt/mysql/mydata/invoice/invoice_id/.max
  或者指向
  /mountpoint/database/table/field
  和
  /mnt/mysql/mydata/invoice/3
  
  同样的就可以返回一行的 min/max/sum/avg 等数值。
  这能很快并且很容易地实现。
  
  /mnt/mysql/mydata/.keys/
  /mnt/mysql/mydata/.keys/invoice_id/
  /mnt/mysql/mydata/.keys/payee/
  
  符号连接到主键:
  /mnt/mysql/mydata/.keys/.primary_key/ 
  实际上指向
  /mnt/mysql/mydata/.keys/invoice_id/
  
  还有一些隐藏文件提供键类型:
  /mnt/mysql/mydata/.keys/invoice_id/.type
  /mnt/mysql/mydata/.keys/payee/.type
  
  第一个文内容为:¨PRIMARY KEY¨ 第二个为 ¨KEY¨ 。
  另外还可以用索引来排序记录,如果读取下面的目录:
  
  /mnt/mysql/mydata/.keys/payee/asc/
  
  PHP 的readdir() 函数就以升序返回数据的符号连接。
  
  另外还有一些全局函数:
  
  /mountpoint/.version
  /mountpoint/.last_insert_id
  /mountpoint/.uptime
  /mountpoint/database/.raid (0/1)
  /mountpoint/database/.type (ISAM/MyISAM/HEAP/DBD)
  /mountpoint/database/.tables
  /mountpoint/database/table/.created
  /mountpoint/database/table/.last_updated
  /mountpoint/database/table/.last_checked
  /mountpoint/database/table/.count
  
  六、写权限
  在开发的第二阶段,会有措施执行SQL 语句。现在的思路是:
  
  采用目录:
  /mountpoint/database/.command/
  
  然后执行命令,把SQL 语句作为目录建立。
  或者建立目录把SQL 语句作为文件放入这个目录。
  
  两个方案都有优点,第一个方案可以重新使用SQL 语句,但是这样的目录名实在不敢令 人苟同。第二个方案采用信号量文件,语句执行完毕就删除这个文件,没有任务使用时, 目录也被删除。对于那些慢速的查询响应,可以选择timeout 的时间。
  
  七、权限管理
  
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.