missing delimiters when mysql output is redirected to log file

Hi,

Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3.
Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file

~Thanks

Step-1: Execute command

> mysql -utest -ptest -htesthost testdb -e "select * from student;"
+---------+--------+------------+
| name    | gender | student_id |
+---------+--------+------------+
|         | M      |          1 |
| newname | M      |          2 |
+---------+--------+------------+

Step-2: Redirect output to log file

> mysql -utest -ptest -htesthost testdb -e -e "select * from student;" &>log_file

Step-3:Cat contents of log file

> cat log_file
name    gender  student_id
        M       1
newname M       2

why is & ? to run background ?

 &>log_file

@itkamaraj: &> is shorthand for 2>&1 >
@newbielgn: When not writing to a terminal, the mysql command will remove the table "lines". You can force that by using the -t option (see here).

2 Likes

Thanks @pludi.
-t worked.

> mysql -t -utest -ptest -htesthost testdb -e -e "select * from student;" &>log_file
  
> cat log_file
+---------+--------+------------+
| name    | gender | student_id |
+---------+--------+------------+
|         | M      |          1 |
| newname | M      |          2 |
+---------+--------+------------+