File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
10
10
11
11
For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
12
12
13
- _ 1433 TILs and counting..._
13
+ _ 1434 TILs and counting..._
14
14
15
15
---
16
16
@@ -607,6 +607,7 @@ _1433 TILs and counting..._
607
607
- [ Display Output In A Vertical Format] ( mysql/display-output-in-a-vertical-format.md )
608
608
- [ Doing Date Math] ( mysql/doing-date-math.md )
609
609
- [ Dump A Database To A File] ( mysql/dump-a-database-to-a-file.md )
610
+ - [ Echo A Message From A SQL File] ( mysql/echo-a-message-from-a-sql-file.md )
610
611
- [ Ignore Duplicates When Inserting Records] ( mysql/ignore-duplicates-when-inserting-records.md )
611
612
- [ List Databases And Tables] ( mysql/list-databases-and-tables.md )
612
613
- [ Run Statements In A Transaction] ( mysql/run-statements-in-a-transaction.md )
Original file line number Diff line number Diff line change
1
+ # Echo A Message From A SQL File
2
+
3
+ Let's say we have a SQL file that we run to seed our database. We want to echo
4
+ a message to stdout at the beginning of that file's execution. We can do this
5
+ with [ a MySQL client _ shell
6
+ command_ ] ( https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-commands.html ) .
7
+ Specifically, we need to use the ` \system ` or ` \! ` command to run our system's
8
+ ` echo ` command.
9
+
10
+ Here is what that could look like:
11
+
12
+ ``` sql
13
+ \! echo ' *****************************************'
14
+ \! echo ' * *'
15
+ \! echo ' * Loading seed data into the database *'
16
+ \! echo ' * *'
17
+ \! echo ' *****************************************'
18
+
19
+ insert into products ...
20
+ ```
21
+
22
+ That message banner will be output when you run the script.
23
+
24
+ ``` bash
25
+ $ mysql -h ::1 -P 3306 -u root -D local_database < seed_data.sql
26
+
27
+ *****************************************
28
+ * *
29
+ * Loading seed data into the database *
30
+ * *
31
+ *****************************************
32
+ ```
You can’t perform that action at this time.
0 commit comments