Exporting table from Amazon RDS into a csv file

前端 未结 6 1370
后悔当初
后悔当初 2020-11-29 17:43

I have a mysql database running in Amazon RDS, and I want to know how to export an entire table to csv format. I currently use mysql server on Windows to query the Amazon da

6条回答
  •  隐瞒了意图╮
    2020-11-29 18:38

    First of all, Steffen's answer works in most cases, I up-voted it and I have myself used it for several years.

    I recently encountered some larger and more complex outputs where "sed" was not enough and decided to come up with a simple utility to do exactly that.

    I build a module called sql2csv that can parse the output of the MySQL CLI:

    $ mysql my_db -e "SELECT * FROM some_mysql_table" 
    
    +----+----------+-------------+---------------------+
    | id | some_int | some_str    | some_date           |
    +----+----------+-------------+---------------------+
    |  1 |       12 | hello world | 2018-12-01 12:23:12 |
    |  2 |       15 | hello       | 2018-12-05 12:18:12 |
    |  3 |       18 | world       | 2018-12-08 12:17:12 |
    +----+----------+-------------+---------------------+
    
    $ mysql my_db -e "SELECT * FROM some_mysql_table" | sql2csv
    
    id,some_int,some_str,some_date
    1,12,hello world,2018-12-01 12:23:12
    2,15,hello,2018-12-05 12:18:12
    3,18,world,2018-12-08 12:17:12
    

    You can also use the built in CLI:

    sql2csv -u root -p "secret" -d my_db --query "SELECT * FROM some_mysql_table;"
    
    1,12,hello world,2018-12-01 12:23:12
    2,15,hello,2018-12-05 12:18:12
    3,18,world,2018-12-08 12:17:12
    

    More info https://github.com/gabfl/sql2csv

提交回复
热议问题