Reputation: 21
It seems that whenever I tried to import an SQL file from D:\src\database\files\books.sql using the command from command line
source D:\src\database\files\books.sql;
It failed, the error said that it failed to open the file. But when I tried to import the SQL file directly from D:\books.sql;
source D:\books.sql;
It works fine.
Does anyone know how to fix it?
The following are the command lines used to import the SQL file
mysql -u root -p books
use books;
database changed
source D:\books.sql;
It worked
Now when I tried to put the file in another folder, for example, D:\src\database\files
I decided to create another database named listing and import the SQL file to this database
CREATE DATABASE listing;
use listing;
source D:\src\database\files\books.sql;
It didn't work
failed to open the file
Upvotes: 2
Views: 374
Reputation: 6844
use as per below-
Go to command prompt and connect mysql
CREATE DATABASE listing;
use listing;
source D:/src/database/files/books.sql;
Upvotes: 0
Reputation: 296
In MySQL ,you can use the command
>>mysql -u username -password=<your_mysql_password> database_name < books.sql
There are various mysql GUI client tools like sqlyog, where-in you can import the data from CSV,sql,Excel formats without writing arduous commands. It just executes the sql file into the selected database.
Upvotes: 0
Reputation: 1526
This is how you can do it:
mysql -u username -p databasename < somefile.sql
Note: You will be prompted for the password.
Upvotes: 2