MySQL File System

Source: Internet
Author: User
Tags copy file system include connect mysql backup
Mysql

Actually, it's not a file system in the usual sense, it doesn't have disk space,
Instead, you use the MySQL daemon to store the data. You can put SQL tables and
Some functions are implemented through the file system.

First, how to achieve?

Let's take a look at the usage example:

[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 22:21. Uptime
Dr-xr-xr-x 1 root 4096 dets 22:21 test
Dr-xr-xr-x 1 root root 4096 dets 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/

Second, why do you do this?

In some cases, doing so can make work easier. MySQL and file systems can be called databases, but there are
With a very different concept and advantages and disadvantages. In a file system, objects can be quickly and easily found, even if the name is changed
Words can also be found quickly. Every beginner should probably learn to move/copy/rename/delete such an operation.
But SQL is different,
He manipulates the data stored on the file system through the application. And the MySQL file system to do the SQL user
Level. Users can manipulate the database in the way they know it.

-Any new product needs to access data through the network, must support some protocols and possible other ways to pass
Over the network Access file system. MySQL tables can be accessed in this way, even if MySQL is not ported to
The corresponding platform.

-Backup and versioning, the normal file system can be implemented by any backup software. Data can be passed by diff
To compare and use CVS to control the version.

-Shorter programming time, sometimes people need to save simple data, like the current date or the name of the site, these numbers
According to few changes, common methods need to be used:

Connect server-> Select Database-> execute command-> store results

And the use of MySQL file system, only need a word: (PHP implementation)

Include (¨/mountpoint/database/table/field¨);

Or, in another way, to express:

Include (¨/mnt/mysql/sitedata/topic/todaytopic¨);


This is easy to understand and takes up less space. /mnt/mysql can also be shared by Samba to achieve
Modify SQL database directly
The purpose. Can write text to the database directly, or use the Copy/paste function to put the picture into the database, this is more than
Perl or PHP writing a hundreds of-line program is much more labor-saving.


Third, what is the performance?

By the time this article was published, the file system was still in prototype development, so the speed was not ideal.
Some database functionality can be faster than using SQL when it comes to a formal release. Of course, many still can't and
In the case of SQL, many complex queries are still required to be done through SQL statements, whether in terms of performance or functionality. But
Is that this saves a lot of time for development and training, so it is also a savings in terms of efficiency.

Four, supported table types:
The file system currently supports all of the table types: Myisam,dbd,heap,isam.

Five, other features:

The first step in the development of the implementation is only read, will soon be able to read and write version out. The current plan is to put the database
objects are mapped to file and directory objects. Let's take a look at the example:


--8<-----------------------------
#建立表

CREATE TABLE Invoice (
invoice_id Int (a) unsigned not NULL auto_increment,
Invoice_no Int (a) unsigned DEFAULT ' 0 ' not NULL,
Payee char (+) DEFAULT ' not NULL,
PRIMARY KEY (invoice_id),
KEY Payee (Payee)
);

# Insert Data

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

Because MySQL has no way to use the record number, we have to create a primary key.
The following directory structure is available:

/mountpoint/database/table/primary_key/field

In this way, each file row that is listed now is different, and the file tree is structured as follows:

/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

In addition, there is a second option that can be used:

/mountpoint/database/table/.table
And
/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


These files are implied to prevent duplication, and are primarily used for easy viewing through a text file browser.

Now, in those that need to use SQL statements to search for the smallest, largest, and last data, you can connect to the real by symbolic
It is now:

/mountpoint/database/table/primary_key/.max
Or
/mnt/mysql/mydata/invoice/invoice_id/.max
or point to
/mountpoint/database/table/field
And
/mnt/mysql/mydata/invoice/3

Similarly, you can return a row of min/max/sum/avg values.
This can be achieved quickly and easily.

/mnt/mysql/mydata/.keys/
/mnt/mysql/mydata/.keys/invoice_id/
/mnt/mysql/mydata/.keys/payee/

Symbol to connect to primary key:
/mnt/mysql/mydata/.keys/.primary_key/
Actually point to
/mnt/mysql/mydata/.keys/invoice_id/

There are also some hidden files that provide key types:
/mnt/mysql/mydata/.keys/invoice_id/.type
/mnt/mysql/mydata/.keys/payee/.type

The first text reads: ¨primary Key¨ the second is ¨key¨.

You can also use indexes to sort records, if you read the following directory:

/mnt/mysql/mydata/.keys/payee/asc/

PHP's Readdir () function returns a symbolic connection to the data in ascending order.

In addition, there are global functions:

/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


Six, write permission?

In the second phase of development, there are measures to execute SQL statements. Now the idea is:

Use directory:
/mountpoint/database/.command/

Then execute the command to create the SQL statement as a directory.
or create a directory to put the SQL statement as a file into this directory.

Two scenarios have advantages, the first scheme can reuse SQL statements, but such directory names do not make
People agree. The second scenario uses a semaphore file, which deletes the file when the statement is executed, and when no task is used,
The directory is also deleted. For those slow query responses, you can choose the timeout time.

VII. Rights Management
In the area of rights management, you can use UNIX's rights management approach, which seems to be the best scenario.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.