Today I was working on a Python project for a
customer, and had to add some additional
tables to an existing MySQL database. I
normally add the SQL statements to a text
file, using the extension 'sql' and feed this
file to the mysql
client program
as follows:
mysql -uroot -p < file.sql
Note that since I always add a USE
db_name
to such text files
there is for me no need to specify the
database in the above command.
But since I had already a terminal open
running the mysql
client program
interactively I was wondering if there was an
easy way to execute the text file from the
mysql prompt. And after a Google search I
found the answer; there is a
source
command, that can be
"abbreviated" to \.
:
mysql> source file.sql
or using the short version of the command:
mysql> \. file.sql
Not related, but another result in Google taught me how to change the mysql prompt.