MySQL command import method to export data table records (select Load data)

Source: Internet
Author: User
Tags mysql database

MySQL database Import Export command More common is the use of mysqldump source these two commands. This article shares a different, faster and more convenient way to import and export data.

(1) Export data

A, use the default path

SELECT * from data table name into outfile ' text name. txt ';
Example:

/* The data in the Phpernote table is exported and saved to the C-disk directory, save as a phpernote.txt file * *

SELECT * from Phpernote into outfile ' c:\phpernote.txt ';

b, specify the path to store

SELECT * from data table name into outfile ' d:\ text name. txt ';
C, export the fields specified by the datasheet

Select Field Name 1, field name 2 From data table name into outfile ' text name. txt ';
(2) Import data

A, the record contains all the fields of the datasheet

Load Data infile ' text name. txt path ' into table table name; Import record contains all fields

B, the record contains the data table specified fields

Load Data infile ' text name. txt ' into table datasheet name (field name 1, field name 2)

Note: the sort of field names should be sorted in accordance with the specified field names exported

The following error may be encountered when customizing the stored path:

Mysql> SELECT * from patent into outfile '/home/a ';
ERROR 1 (HY000): Can ' t create/write to file '/home/a ' (errcode:13)

Again, refer to a solution:

Obviously, this is due to permission issues, and the main problem is figuring out how permissions are set.
Ubuntu uses AppArmor as a program permission limit, and Fedora uses SELinux as a program permission limit. In Linux, the previous rights management, through the user-bound, now there is a privilege mechanism to set the program access rights, such as:
sudo mysqldump--t db; If you do not start the program Rights Management, mysqldump get root permissions, you can operate in any file.
sudo mysqldump-t db; if AppArmor is enabled in Ubuntu, even root permissions are qualified according to the program's access rights.

So we can add the directories that need to be accessed to the AppArmor configuration file:

sudo gedit/etc/apparmor.d/usr.sbin.mysqld
Add the following:

/data/* RW,
Then, Sudo/etc/init.d/apparmor restart

I'm just looking for a usr.sbin.mysqld directory (/var/log/mysql/) in the right place, because the custom directory doesn't seem to work.
jesse@jesse-desktop:/var/log/mysql$

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.