Home > database >  Trying to import SQL File with command
Trying to import SQL File with command

Time:02-11

I want to import a sql file to a database. I work on Windows 10 and I want to use the commands lines.

I tried this :

C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql -u {username} -p{password} db_test < F:\BDD\_databasetest\test.sql

But I have an error : "C:\Program not recognized"

So I tried to go by step :

cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysql -u {username} -p{password}
mysql db_test < F:\BDD\_databasetest\test.sql

But at the third command, I have this error :

ERROR: Unknown command '\B'. ERROR: Unknown command '_'. Outfile disabled.

For the command "mysql db_test < F:\BDD_databasetest\test.sql" I'm not sure about the "mysql" part so I tried both, with the same error. I tried to double the \ in the path, and I tried to used '' and "" for the path, without succes.

PS : english is not my native language. I clarifications are needed, don't hesitate.

CodePudding user response:

with the first mysql commad you can't to the database so the mnexe must be a sql command

For both options the database has to exit already, if in the sql is no CREATE DATABASE ...

use

mysql -u root -p db_test < D:\BDD\_databasetest\test.sql

or

mysql -u {username} -p{password}

mysql> use db_test ;

mysql> source D:/BDD/_databasetest/test.sql;

Note in the last command the / instad of \

CodePudding user response:

So as the OP confirmed, double-quoting the Windows path helped: "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql" -u {username} -p{password} db_test < F:\BDD\_databasetest\test.sql

The error message 'error : "C:\Program not recognized"' suggest that it is not a mysql-related issue.

  • Related