# MySQL: redirection of the stdout on a file



## vince66 (Jun 28, 2018)

Hello guys !

Is it possible redirect the standard output of the mysql promp to a text file ?

Thake as example the following statement.

*mysql>* SELECT * FROM USERS;

```
+---------+----------------+---------------+--------------+
| USER_ID | USER_FIRSTNAME | USER_LASTNAME | USER_ADDRESS |
+---------+----------------+---------------+--------------+
|      1  |       John     |     Smith     |   Street 2   |
|      1  |      Carl      |    Peterson   |  Street 25   |
|      1  |        Mary    |  O'Conner     |   Street 5   |
+---------+----------------+---------------+--------------+

3 rows in set (0.00 sec)
```
Is it possible print on a text file the table USERS called by the SELECT command ?

Thanks in advance.


----------



## scottro (Jun 29, 2018)

Yes, but the easiest way I've found to do it is, if you were user root, for example and you have a database called clients with a table users

```
mysql -uroot -p -e "select * from users" clients > user.list
```


----------



## SirDice (Jun 29, 2018)

`SELECT * INTO OUTFILE '/tmp/output.txt' FROM users;`

https://dev.mysql.com/doc/refman/5.5/en/select-into.html


----------



## ljboiler (Jun 29, 2018)

Or there are the *tee* and *notee* commands.
https://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html">


----------

