The output formatting of the MySQL client is amazing. I didn't notice it before. I 'd like to share it here:
$ Mysql-uroot-e "show global status like 'uptime '"
+ ----- + --- +
| Variable_name | Value |
+ ----- + --- +
| Uptime | 2174838 |
+ ----- + --- +
$ Mysql-uroot-e "show global status like 'uptime'">/tmp/test
[Mysql @ dev81 ~] $ Cat/tmp/test
Variable_name Value
Upload 2174855
Have you found anything strange? The formatted symbols are gone! With the same command, after redirecting to a file, the output changes!
+ ----- + --- +
| Variable_name | Value |
+ ----- + --- +
| Uptime | 2174838 |
+ ----- + --- +
Changed
Variable_name Value
Upload 2174855
I thought for a long time and didn't want to understand it. When asked about the lower part of the qushan city, he started to use strace without saying anything, and immediately found the secret.
$ Strace mysql-uroot-e "show global status like 'uptime '"
......
......
Write (1, "+ ----- + --- + \ n", 28 + ----- + --- +
) = 28
Write (1, "| Variable_name | Value | \ n", 28 | Variable_name | Value |
) = 28
Write (1, "+ ----- + --- + \ n", 28 + ----- + --- +
) = 28
Write (1, "| Uptime | 2175430 | \ n", 29 | Uptime | 2175430 |
) = 29
Write (1, "+ ----- + --- + \ n", 28 + ----- + --- +
) = 28
Poll ([{fd = 3, events = POLLIN | POLLPRI}], 1, 0) = 0
Write (3, "\ 1 \ 0 \ 0 \ 1", 5) = 5
Shutdown (3, 2/* send and receive */) = 0
Close (3) = 0
Exit_group (0) =?
Process 24577 detached
$ Strace mysql-uroot-e "show global status like 'uptime'">/tmp/test
......
......
Write (1, "Variable_name \ tValue \ nUptime \ t21755 ″..., 35) = 35
Exit_group (0) =?
Process 24581 detached
For different output channels, the MySQL client seems to have a way to capture and adopt different formatting output policies. However, I still don't know the reason why MySQL is doing this. It is estimated that only days will know.