Using mysql command line to generate CSV, can't generate it in any other directory except /tmp -


i creating csv , mysql dumps via mysql command line. creating mysql file can created .sql dump in required directory

 mysqldump  -u"root" -p"root"  dns packet --where="server_id=1 > /var/www/mydatafile/sqldata.sql 

that works okay in case of csv, creates files in tmp folder, can't create files in other location

 mysql -u"root" -p""  dns -e "select * outfile '/var/www/mydatafile/my_csv.csv'  fields terminated ',' lines terminated '\r\n' tablename"; 

it says

error 1 (hy000) @ line 1: can't create/write file '/var/www/mydatafile/my_csv.csv' (errcode: 13) 

i have given permission www directory still gives same error...may know reason behind not creating csv anyother location while sql can generated easily..

your directory /var/www/mydatafile/ has writable mysql user (usually mysql). can check user in file my.cnf (in debian/ubuntu based, located in /etc/mysql/ ).

the first command works because generate sql instruction stdout , redirect output file, use current user environment.

the second command internal mysql, correct permissions required mysql user.

edit: can alternatively use mysqldump generate csv command this:

mysqldump -u"root" -p"root"  dns packet -p -t --fields-terminated-by=, --lines-terminated-by="\r\n" 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -