Let's start with a comma ('), vertical bar (|) Separated data. Many people would say that using
The code is as follows |
Copy Code |
Mysql-uuser-ppwd dbname-e "$sql" |
For export.
where $sql uses
The code is as follows |
Copy Code |
SELECT * from ' tablename ' WHERE xxx to outfile "Specify File path Strength" FIELDS terminated by "|"
|
This is often a lot of people will report no permissions and other inexplicable mistakes.
Error One
The code is as follows |
Copy Code |
Errorerror 1045 (28000) at line 1:access denied for user ' qinghua ' @ ' localhost ' (using Password:yes) |
Error two
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 one is because the ordinary user does not have permission to execute, error two is because there is no permission to wear the file "AA".
The right thing to do should be
The code is as follows |
Copy Code |
shellmysql-uqinghua-p123456 Qinghua--e "select * from Qinghua.user where 1 to outfile ' outfile ' FIELDS terminated by ' |'" |
The file that it wears will appear in the database folder of the MySQL DataDir directory.
If you want to create a file in the specified directory. Then you must give the directory MySQL write permission.
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.111cn.net/database/mysql/42121.htm related articles
–w set the conditions for the export.
The –NO-CREATE-DB database is not exported.
–no-create-info does not create a table structure.
–xml export XML Format files.
–skip-add-drop-table does not create a Delete table structure statement.
MySQL data import typically uses Mysql-uuser-ppwd dbname < Xxx.sql, or imports using source.
Reference Address:
Http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Http://dev.mysql.com/doc/refman/5.1/zh/replication.html generates binary logs for dual-machine hot standby
And look at other ways.
The export process is as follows: Call method ****.php?table=tablename
This simple program saves a table at once!! Each behavior a field of data!!
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 begins converting data to text ... "; $handle = fopen ("$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 programs are as follows: Use the same top!
code is as follows |
copy code |
if ($table = "" ) exit (); mysql_connect ("localhost", "name", "password"); mysql_select_db ("database"); $message = File ("$table. 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); The Echo $k. "; } Echo "OK"; ?> |