0

As shown in the code below I want to export my tables to the location in 'secure_file_priv', as it is I just manually copy and paste it but I'd like to be able to just use it's value.

USE Library;


show VARIABLES LIKE 'secure_file_priv';

set mylocation := (VARIABLES LIKE 'secure_file_priv');

SELECT 'Id', 'Name', 'Birthplace', 'Birthday', 'Gender'
UNION ALL
SELECT Id, Name, Birthplace, Birthday, Gender
    FROM Author
    INTO OUTFILE '/var/lib/mysql-files/author.csv'
    FIELDS TERMINATED BY ',' 
    OPTIONALLY ENCLOSED BY ''
    LINES TERMINATED BY '\n';

Instead of manually writing '/var/lib/mysql-files/author.csv' I'd like to be able to use the 'secure_file_priv' variable's value.

1

1 Answer 1

0
SET @mylocation = (SELECT @@secure_file_priv);

SELECT 'Id', 'Name', 'Birthplace', 'Birthday', 'Gender'
UNION ALL
SELECT Id, Name, Birthplace, Birthday, Gender
    FROM Author
    INTO OUTFILE @mylocation
    FIELDS TERMINATED BY ',' 
    OPTIONALLY ENCLOSED BY ''
    LINES TERMINATED BY '\n';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.