Redirecting a .sql
file into the MySQL CLI works because that's the format that mysqldump
produces. And people usually call mysqldump
to dump a whole database, so they get one file afterwards.
The username and password are dependant on what's been setup on the database instance you want to reload the data in to. On a clean, empty install, the MySQL root user will work (and probably won't have a password). On an established install, you should find an appropriate user. The user you use will need substantial permissions as it needs to create and write to tables.
The .sql
file may have CREATE database
and USE database
statements near the top. If this is present, then make sure that database does not exist before you pipe the file in. If not, you will need to find out what name is expected by whatever program will be using the database.
As for piping another file in in a different directory, this is simple shell notation. The < filename
notation fully supports paths so you can do < some/other/path/filename.sql
or < ~/sql/filename.sql
, for example. (Note that I've assumed you're using a Unix shell.)