1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Echo A Message From A SQL File as a MySQL TIL

This commit is contained in:
jbranchaud
2024-05-31 10:07:23 -05:00
parent 84e2c9c6f4
commit e91b163571
2 changed files with 34 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
# Echo A Message From A SQL File
Let's say we have a SQL file that we run to seed our database. We want to echo
a message to stdout at the beginning of that file's execution. We can do this
with [a MySQL client _shell
command_](https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-commands.html).
Specifically, we need to use the `\system` or `\!` command to run our system's
`echo` command.
Here is what that could look like:
```sql
\! echo '*****************************************'
\! echo '* *'
\! echo '* Loading seed data into the database *'
\! echo '* *'
\! echo '*****************************************'
insert into products ...
```
That message banner will be output when you run the script.
```bash
$ mysql -h ::1 -P 3306 -u root -D local_database < seed_data.sql
*****************************************
* *
* Loading seed data into the database *
* *
*****************************************
```