MySQL Reference Manual --- MySQL file system _ MySQL

Source: Internet
Author: User
This is a Linux file system under development. MySQL databases on Linux can be processed as file systems. The development team hopes to get more suggestions. the following article translated from: in fact, this is not a file system in the general sense, it has no disk space, instead, the MySQL daemon is used to store data. You can use the SQL table and some functions in the document Manual.


This is a Linux file system under development. MySQL databases on Linux can be processed as file systems. The development team hopes to get more suggestions. the following article translated from:
  
In fact, this is not a file system in the general sense. it does not have disk space, but uses the MySQL daemon to store data. SQL tables and some functions can be implemented through the file system.
  
   1. how to implement it?
Let's look at the instance:
  
[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: 01e50d401b00000049444c3a436f000026146532f46696c6553797374656d3a312e
3001000000000000000000000030000000010100000a0000003132372e302e302e310008041800
20171000000009224bc335663462a0000000ef7ae13c0943c59f)
  
[Root @ localhost/root] # ls-la/mnt/mysql/
  
Total 0
  
-R-xr-x 1 root 4096 dets 29. uptime
Dr-xr-x 1 root 4096 dets 29 test
Dr-xr-x 1 root 4096 dets 29 22: 21 mysql
  
[Root @ localhost/root] # cat/mnt/mysql/. uptime
  
1994
  
[Root @ localhost/root] # cat/mnt/mysql/user/Host
  
Cpq. spam. ee
Cpq. spam. ee
Localhost
Localhost
Localhost
Localhost
Localhost
Localhost
  
[Root @ localhost/root] # cat/mnt/mysql/user/Insert_priv
N
N
N
N
N
N
Y
Y
  
[Root @ localhost/root] # umount/mnt/mysql/
  
   2. why?
In some cases, this can make your work easier. Both MySQL and file systems are called databases, but they have different concepts and advantages and disadvantages. In a file system, objects can be quickly and easily found, even if the name is changed. Every beginner should probably learn operations like move/copy/rename/delete. But SQL is different. it uses applications to manipulate data stored in the file system. The MySQL file system implements SQL at the user level. Users can operate databases in the way they know.
  
-If any new product needs to access data through the network, it must support some protocols and other possible methods to access the file system through the network. MySQL tables can be accessed in this way, even if MySQL is not migrated to the corresponding platform.
  
-Backup and version control: common file systems can be implemented through any backup software. You can use diff to compare the data and use cvs to control the version.
  
-For a shorter programming time, sometimes people need to save simple data, such as the current date or site name, which rarely changes. The common method needs to be:
  
Connect to the server-> Select database-> Execute command-> store results
  
After using the MySQL file system, you only need one sentence: (PHP implementation)
  
Include (?/mountpoint/database/table/field );
  
Alternatively, use the following expression:
  
Include (?/mnt/mysql/sitedata/topic/todaytopic );
  
This makes it easy to understand and consumes less space. You can also share/mnt/mysql through SAMBA to directly modify the SQL database. Writing text directly to the database, or using the copy/paste function to put images into the database is much more effort-saving than writing hundreds of lines of programs using Perl or PHP.
  
   3. What is the performance?
At the time of this article, the file system is still in the prototype development stage, so the speed is not ideal. When it comes to official release, some database functions will be faster than using SQL. Of course, many of them cannot be compared with SQL. in terms of performance and functionality, many complex queries still need to be completed through SQL statements. However, this saves a lot of development and training time, so efficiency is also a saving.
  
   4. supported table types:
Currently, this file system supports all table types: MyISAM, DBD, HEAP, and ISAM.
  
   5. other features:
In the first step of development, only read-only is implemented, and a read/write version will soon be available. The current plan is to map database objects to files and directory objects. Let's take a look at the example:
  
-- 8 <-----------------------------
# Creating a table
  
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 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 cannot use the record number, we must create a primary key. The following directory structure is available:
  
/Mountpoint/database/table/primary_key/field
  
In this way, the structure of the file tree is 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, the second method 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 hidden to prevent duplication. They are mainly used for viewing in a text file browser.
  
Currently, the minimum, maximum, and last data can be searched by using SQL statements.
Now:
  
/Mountpoint/database/table/primary_key/. max
Or
/Mnt/mysql/mydata/invoice/invoice_id/. max
Or point
/Mountpoint/database/table/field
And
/Mnt/mysql/mydata/invoice/3
  
Similarly, the min, max, sum, avg, and other values of a row can be returned.
This can be implemented quickly and easily.
  
/Mnt/mysql/mydata/. keys/
/Mnt/mysql/mydata/. keys/invoice_id/
/Mnt/mysql/mydata/. keys/payee/
  
Symbol to connect to the primary key:
/Mnt/mysql/mydata/. keys/. primary_key/
Actually point
/Mnt/mysql/mydata/. keys/invoice_id/
  
There are also some hidden files that provide the key type:
/Mnt/mysql/mydata/. keys/invoice_id/. type
/Mnt/mysql/mydata/. keys/payee/. type
  
The content of the first article is: "primary key", and the second is "KEY.
You can also use indexes to sort records. if you read the following directories:
  
/Mnt/mysql/mydata/. keys/payee/asc/
  
The PHP readdir () function connects to the symbols that return data in ascending order.
  
There are also some global functions:
  
/Mountpoint/. version
/Mountpoint/. last_insert_id
/Mountpoint/. uptime
/Mountpoint/database/. raid (1, 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
  
   6. write permission
In the second stage of development, measures will be taken to execute SQL statements. The current idea is:
  
Directory used:
/Mountpoint/database/. command/
  
Then run the command to create the SQL statement as a directory.
Or create a directory to put the SQL statement as a file.
  
Both solutions have advantages. The first solution can use SQL statements again, but such a directory name cannot be the same. The second solution uses a semaphore file. after the statement is executed, the file is deleted. when no task is used, the directory is also deleted. For slow query responses, you can select a timeout time.
  
   VII. permission management
  

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.