MySQL中文参考手册---MySQL 文件系统_MySQL
手册
这是一款正在开发中的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 的时间。
七、权限管理

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



HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

Xiaomi car software provides remote car control functions, allowing users to remotely control the vehicle through mobile phones or computers, such as opening and closing the vehicle's doors and windows, starting the engine, controlling the vehicle's air conditioner and audio, etc. The following is the use and content of this software, let's learn about it together . Comprehensive list of Xiaomi Auto app functions and usage methods 1. The Xiaomi Auto app was launched on the Apple AppStore on March 25, and can now be downloaded from the app store on Android phones; Car purchase: Learn about the core highlights and technical parameters of Xiaomi Auto, and make an appointment for a test drive. Configure and order your Xiaomi car, and support online processing of car pickup to-do items. 3. Community: Understand Xiaomi Auto brand information, exchange car experience, and share wonderful car life; 4. Car control: The mobile phone is the remote control, remote control, real-time security, easy
