This is dirty and ugly. It is only suitable for the particular situation where all you have is a PHP-*-admin and the server is running with the --secure-file-priv
option, so then you cannot use the INTO OUTFILE '/path/to/export.csv'
clause in your query.
What you can do is parse lines of CSV with ... wait for it!, CONCAT
, then copy the results and paste them into a file.
Here's an example, where I needed SQL format (it'd be trivial to adapt it for CSV):
SELECT CONCAT(
"('",
`username`, "', '",
`password`, "', '",
`first_name`, "', '",
`last_name`, "', '",
`gender`, "'),"
) AS `row`
FROM `users`
WHERE `role` != 'Not set'
AND `user_status` = 'Active'
ORDER BY `role`, `gender`, `user_id`
LIMIT 200
That gives nice, ready for import output similar to this:
('jane', '3d7ff...', 'Jane', 'Doe', 'Female'),
('john', 'd2a33...', 'John', 'Doe', 'Male'),
...
REPLACE()
in your query to have the quotes escaped.