I want to execute a text file containing SQL queries, in MySQL.
I tried to run source /Desktop/test.sql
and received the error:
mysql> . \home\sivakumar\Desktop\test.sql ERROR: Failed to open file '\home\sivakumar\Desktop\test.sql', error: 2
Any idea on what I am doing wrong?
So many ways to do it.
If you get errors from the command line, make sure you have previously run
This must be run from within the mysqld.exe directory, hence the CD.
Hope this is helpful and not just redundant.
My favorite option to do that will be:
I use it this way because when you string it with "" you avoiding wrong path and mistakes with spaces and - and probably more problems with chars that I did not encounter with.
With @elcuco comment I suggest using this command with [space] before so it tell bash to ignore saving it in history, this will work out of the box in most bash.
in case it still saving your command in history please view the following solutions:
Execute command without keeping it in history
extra security edit
Just in case you want to be extra safe you can use the following command and enter the password in the command line input:
I had this error, and tried all the advice i could get to no avail.
Finally, the problem was that my folder had a space in the folder name which appearing as a forward-slash in the folder path, once i found and removed it, it worked fine.
I came here searching for this answer as well, and here is what I found works the best for me: Note I am using Ubuntu 16.x.x
mysql -u <your_user> - p
source file_name.sql
Hope this helps.
Never is a good practice to pass the password argument directly from the command line, it is saved in the
~/.bash_history
file and can be accessible from other applications.Use this instead: