How to import SQL files using command line in MySQL?
P粉459578805
P粉459578805 2023-08-23 10:46:22
0
2
362
<p>I have a <code>.sql</code> file that contains an export from <code>phpMyAdmin</code>. I want to import it into a different server using the command line. </p> <p>I installed Windows Server 2008 R2. I placed the <code>.sql</code> file on <strong><em>C drive</em></strong> and tried this command</p> <pre class="brush:php;toolbar:false;">database_name < file.sql</pre> <p>It doesn't work. I'm getting a syntax error. </p> <ul> <li>How can I successfully import this file? </li> <li>Do I need to create a database first? </li> </ul><p><br /></p>
P粉459578805
P粉459578805

reply all(2)
P粉926174288

mysqldump A common use is to back up the entire database:

mysqldump db_name > backup-file.sql

You can load the dump file back to the server as follows:

Unix

mysql db_name < backup-file.sql

Same in Windows Command Prompt:

mysql -p -u [user] [database] < backup-file.sql

PowerShell

cmd.exe /c "mysql -u root -p db_name < backup-file.sql"

MySQL command line

mysql> use db_name;
mysql> source backup-file.sql;
P粉103739566

try:

mysql -u username -p database_name < file.sql

Check MySQL Options. p>

Note 1: It is best to use the full path of the SQL file file.sql.

Note 2: Use -R and --triggers with mysqldump to save the original database of routines and triggers. They are not copied by default.

Note 3 If the database does not exist yet and the exported SQL does not contain CREATE DATABASE (exported using --no-create-db or -n option) before importing it.

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!