Created
July 20, 2018 12:57
-
-
Save kitzberger/3998fc886db326171f08fb1e8805eca5 to your computer and use it in GitHub Desktop.
Export MySQL into CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Wanna export a joined result? | |
SELECT a.id, a.name, b.name | |
FROM tableA a | |
JOIN tableB b ON a.id = b.rel_id | |
WHERE a.deleted=0 and b.deleted=0 | |
ORDER BY a.name, b.nane | |
INTO OUTFILE '/var/lib/mysql-files/xxxx.csv' | |
FIELDS TERMINATED BY ',' | |
ENCLOSED BY '"' | |
LINES TERMINATED BY '\n'; | |
-- Trouble shooting #1 | |
-- User needs to have the FILE grant | |
mysql> show grants for <user> | |
-- If it's missing, then grant it | |
mysql> GRANT FILE ON *.* TO | |
-- Trouble shooting #2 | |
-- Output path strict? | |
mysql> SHOW VARIABLES LIKE "secure_file_priv"; | |
+------------------+-----------------------+ | |
| Variable_name | Value | | |
+------------------+-----------------------+ | |
| secure_file_priv | /var/lib/mysql-files/ | | |
+------------------+-----------------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment