MariaDB / SQL INTO OUTPUT Error 2

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

MariaDB / SQL INTO OUTPUT Error 2

Postby esgaroth32 » 22. June 2019 13:29

Good day, I am trying to run the following command but it does not seem to work.

Code: Select all
[root@ ]# mysql -pPassword asteriskcdrdb -s -b -e "select 'Account ID','Destination','Operator','Provider','Date','BillSec','Rate id','Cost' UNION select accountcode,dst,'PBX',route_name,date_format(calldate,'%Y/%c/%e %H:%i'),billsec as Duration,route_id,round(cost,5) from cdr where calldate > '$prev_date' and calldate < '$cur_date' and cost > 0 and accountcode='$accountcode' UNION select '','','','','','',concat('R',sum(round(cost,5))),'' from cdr where calldate > '$prev_date' and calldate < '$cur_date' and cost > 0 and accountcode='$accountcode' INTO OUTFILE '/tmp/VoipBilling-$date/CDR/$accountcode-$date.csv' FIELDS TERMINATED BY ',';"


Error is: ERROR 1 (HY000) at line 1: Can't create/write to file '/tmp/VoipBilling-/CDR/-.csv' (Errcode: 2)

Note the filepath in the error code and the filepath specified differs. Almost as if Mariadb does not know to create the folder with the date i.e /tmp/VoipBilling-2019-06-22/CDR/BILLTEST-2019-06-22.csv''

Instead it wants to write it as '/tmp/VoipBilling-/CDR/-.csv'

When I run the same command but change the output path to not use the $date it works. i.e
Code: Select all
[root@ ]# mysql -pPassword asteriskcdrdb -s -b -e "select 'Account ID','Destination','Operator','Provider','Date','BillSec','Rate id','Cost' UNION select accountcode,dst,'PBX',route_name,date_format(calldate,'%Y/%c/%e %H:%i'),billsec as Duration,route_id,round(cost,5) from cdr where calldate > '$prev_date' and calldate < '$cur_date' and cost > 0 and accountcode='$accountcode' UNION select '','','','','','',concat('R',sum(round(cost,5))),'' from cdr where calldate > '$prev_date' and calldate < '$cur_date' and cost > 0 and accountcode='$accountcode' INTO OUTFILE '/tmp/VoipBilling/CDR/accountcode.csv' FIELDS TERMINATED BY ',';"


So it is safe to say this is not a folder permision but the command not being able to create the folder with $date specified.

Please assist
esgaroth32
 
Posts: 1
Joined: 22. June 2019 13:23
XAMPP version: 5.5.6
Operating System: Centos 7

Re: MariaDB / SQL INTO OUTPUT Error 2

Postby Nobbie » 22. June 2019 20:56

You are in the wrong forum here.

Your problem is NOT a MySQL problem, its a lack of Linux knowledge. Proceed to a Linux forum and ask about environment variables in shell commands and the scope of the variables, especially when surrounded by quotes (its a big difference between double quotes and single quotes).

Obviously $date is not expanded in your Linux shell command and there is a reason for it.

esgaroth32 wrote:When I run the same command but change the output path to not use the $date it works.


Yes of course. But still, you are in the wrong forum. This is NOT a linux shell forum.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 58 guests