I want you to know that data import and import can be implemented using mysqldump, a built-in mysql tool, or a custom program. The following describes two methods.
Let's talk about data that is separated by commas (') and vertical bars (|. Many people will say that
The Code is as follows: |
Copy code |
Mysql-uUser-pPwd dbName-e "$ SQL" |
.
Where $ SQL is used
The Code is as follows: |
Copy code |
SELECT * FROM 'tablename' WHERE xxx into outfile "specify file path strength" fields terminated by "|"
|
Many of these errors often report inexplicable errors such as No permissions.
Error 1
The Code is as follows: |
Copy code |
ERRORERROR 1045 (28000) at line 1: Access denied for user 'qinghua' @ 'localhost' (using password: YES) |
Error 2
The Code is as follows: |
Copy code |
ERRORERROR 1 (HY000) at line 1: Can't create/write to file '/home/martin/outfile' (Errcode: 13) |
Error 1: normal users do not have the execution permission. Error 2: users do not have the permission to wear the file "aa ".
Which of the following statements is true?
The Code is as follows: |
Copy code |
SHELLmysql-uqinghua-p123456 qinghua -- e "select * from qinghua. user where 1 into outfile 'outfile' fields terminated by' | '" |
In this way, the file it is wearing will appear in the database folder corresponding to the mysql datadir directory.
If you want to create a file in a specified directory. Then you must grant the mysql write permission to the directory.
The general practice is
The Code is as follows: |
Copy code |
Mkdir-p/home/martin/outdata; Chown mysql. mysql/home/martin/outdata; Sudo chmod 777/home/martin/outdata; SHELLmysql-uqinghua-p123456 qinghua -- e "select * from qinghua. user where 1 into outfile '/home/martin/outdata/outfile 'fields TERMINATED by' | '" |
Mysqldump parameter Introduction: http://www.bKjia. c0m/database/mysql/42121.htm
-W: Set the export conditions.
-No-create-db cannot export the outfitting database.
-No-create-info: no table structure is created.
-Export xml files.
-The skip-add-drop-table statement does not create or delete the table structure.
Mysql Data Import generally uses mysql-uUser-pPwd dbName <xxx. SQL or source for import.
Reference address:
Http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
The http://dev.mysql.com/doc/refman/5.1/zh/replication.html generates binary logs for hot standby
Let's look at other methods.
The Export program is as follows: The call method is ***. php? Table = tablename
This simple program currently saves a table at a time !! Data of one field for each behavior !!
The Code is as follows: |
Copy code |
If ($ table = "") exit (); Mysql_connect ("localhost", "name", "password "); Mysql_select_db ("database "); $ Result = mysql_query ("select * from $ table "); If (mysql_num_rows ($ result) <= 0) exit (); Echo "starts to convert data to text... "; $ Handle = fopen ("Export table.txt", "w "); $ Numfields = mysql_num_fields ($ result ); Fputs ($ handle, $ numfields. "rn "); For ($ k = 0; $ k { $ Msg = mysql_fetch_row ($ result ); For ($ I = 0; $ I <$ numfields; $ I ++) { $ Msg [$ I] = str_replace ("rn", "& php2000mysqlreturn &", $ msg [$ I]); $ Msg [$ I] = str_replace ("n", "& php2000mysqlreturn &", $ msg [$ I]); Fputs ($ handle, $ msg [$ I]. "rn "); } Fputs ($ handle, "------- php2000 dump data program V1.0 for MySQL -------- rn "); } Fclose ($ handle ); Echo "OK "; ?> |
The imported program is as follows: the usage is the same as above!
The Code is as follows: |
Copy code |
If ($ table = "") exit (); Mysql_connect ("localhost", "name", "password "); Mysql_select_db ("database "); $ Message = file ("cmdtable.txt "); Echo $ numfields = chop ($ message [0]); For ($ k = 1; $ k { $ Value = ""; For ($ I = $ k; $ I <($ k + $ numfields-1); $ I ++) { $ Tmp = str_replace ("& php2000mysqlreturn &", "rn", chop ($ message [$ I]); $ Value. = "'". addslashes ($ tmp )."',"; } $ Tmp = str_replace ("& php2000mysqlreturn &", "rn", chop ($ message [$ k + $ numfields-1]); $ Value. = "'". $ tmp ."'"; $ Query = "insert into $ table values (". $ value .")"; Echo mysql_error (); Mysql_query ($ query ); Echo $ k .""; } Echo "OK "; ?>
|