是否可以在.sql扩展名中使用php代码导出数据库?
Example
database name : demodb
db contain two tables
table one : user
table two : registration
答案 0 :(得分:5)
是可能。
<?php
//ENTER THE RELEVANT INFO BELOW
$mysqlDatabaseName ='xxxxxx';
$mysqlUserName ='xxxxxxx';
$mysqlPassword ='myPassword';
$mysqlHostName ='xxxxxxxx.net';
$mysqlExportPath ='chooseFilenameForBackup.sql';
//DO NOT EDIT BELOW THIS LINE
//Export the database and output the status to the page
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ~/' .$mysqlExportPath;
exec($command);
?>
答案 1 :(得分:0)
对mySql db使用 mysqldump 命令:
$command = "/usr/bin/mysqldump -u mysql_username -h mysql_host -p mysql_password database_name> /path_to_export_location/file_name.sql";
exec($command, NULL, NULL);
查看MySQL
中的文档