Home > Database > Mysql Tutorial > body text

How to Export MySQL Data from a Remote Server without Direct Access?

DDD
Release: 2024-11-02 10:42:02
Original
227 people have browsed it

How to Export MySQL Data from a Remote Server without Direct Access?

Exporting MySQL Data without Direct Server Access

When transferring data from a remote MySQL server to your local machine without direct server access or phpMyAdmin, PHP can provide a solution.

PHP-Based Export and Import

To export data from a remote table named "##table##" into a local file "mytable.sql," use the following PHP code:

<code class="php">$file = 'backups/mytable.sql';
$result = mysql_query("SELECT * INTO OUTFILE '$file' FROM `##table##`");</code>
Copy after login

This SQL query exports the entire table into the specified file, which can then be downloaded using a browser or FTP client.

To import the data back into your local database from the "mytable.sql" file, execute the following query:

<code class="php">$file = 'backups/mytable.sql';
$result = mysql_query("LOAD DATA INFILE '$file' INTO TABLE `##table##`");</code>
Copy after login

System Command Method

Alternatively, you can invoke the 'mysqldump' command using PHP's system() function:

<code class="php">$file = 'backups/mytable.sql';
system("mysqldump --opt -h ##databaseserver## -u ##username## -p ##password## ##database | gzip > ".$file);</code>
Copy after login

This command creates a compressed SQL dump of your chosen database and saves it to the specified file. The dump can then be imported using standard MySQL operations.

The above is the detailed content of How to Export MySQL Data from a Remote Server without Direct Access?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!