How to import SQL files using command line in MySQL?
P粉459578805
2023-08-23 10:46:22
<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>
mysqldump A common use is to back up the entire database:
You can load the dump file back to the server as follows:
Unix
Same in Windows Command Prompt:
PowerShell
MySQL command line
try:
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
withmysqldump
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.