/go/csv runs a SELECT query on the server's MariaDB/MySQL database and saves the result as a CSV file. You can export a whole table, chosen columns, or a filtered result, from any database on the server. The query runs with the database root account, so it can read every database. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.
Quick start
# Export a whole table to /root/orders.csv
/go/csv -s "SELECT * FROM shop.orders" -o /root/orders.csv
[!WARNING]
The export file contains your data in plain text and can be large. Store it somewhere safe and delete it when you no longer need it. The query is also saved in/var/log/go/csv.log, so don’t put passwords or other secrets in it.
Options
| Option | Required | Notes |
|---|---|---|
-s <query> |
Yes | A single SELECT statement, without a trailing semicolon. Name the database in the query (database.table). |
-o <file> |
Yes | The file to create. A relative path is relative to the current directory. An existing file is overwritten. Don’t use spaces in the name. |
If you pass an unknown option, the command prints Usage: csv [-s] SQL Query [-o] Output File Name, but it keeps going with the values it has. Always give both options.
Examples
# Export rows that match a condition (single quotes inside the query)
/go/csv -s "SELECT * FROM crm.DLD WHERE Mobile LIKE '20%' OR Keywords LIKE '%egypt%' GROUP BY Mobile" -o egypt.csv
# Export two columns
/go/csv -s "SELECT id, email FROM shop.users" -o /root/users.csv
# Add a header row by putting it first with UNION ALL
/go/csv -s "SELECT 'id','email' UNION ALL SELECT id, email FROM shop.users" -o /root/users.csv
# Check the result
head /root/users.csv
wc -l /root/users.csv
Output
The command prints nothing when it works. Errors from the database are shown on screen.
Every run is logged with its arguments and a timestamp, for example [Nov 20 09:15:02]# csv -s SELECT * FROM shop.orders -o /root/orders.csv, to /var/log/go/csv.log.
File format
| Setting | Value |
|---|---|
| Separator | Comma. |
| Quoting | Every value is wrapped in double quotes, numbers included. |
| Line ending | A new line (\n). |
| Header row | None. The file contains only data rows. |
| Special characters | Escaped with a backslash. Quotes inside a value are written as \", not doubled. |
| Empty values | NULL is written as \N. |
See the full reference at /go/csv and the GoAdmio command index.
GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.
