I want to execute an sql query (stored in a text file) from the command line.
From what I have found, I can see that this should work:
mysql -u root -p < create_database.sql
I get an error when I try to do this and wanted help understanding.
Root can remain root, correct? Or do I have to specify my username in place of the word root? I thought that -u would prompt me for my username and -p would prompt me for a password after the above was typed in, but I’m not sure as I’m a beginner at running from the command line.
Also, do I have to be in the directory of where this file is located for this to work? I wouldn’t think so since it is being redirected to the specific file…
Thank you in advance for any help 🙂
You should really follow -u with your username rather than creating databases under root, and either use the full path to the file or navigate to the directory it’s in.
You might want to log in and use the source command.