Reputation:
I have created a batch script which is supposed to execute the SQL file in the same directory and then pause, where I connect to MYSQL and issue the commands inside of the SQL file. For some reason when I directly paste these lines into a command window, it works fine. When I have it setup as follows, I receive an Access Denied error. Can anyone please point out what I am doing wrong?
BAT File:
cmd < script.sql
pause
Script.SQL file
@echo off
mysql --host=localhost --user=dbuser --password=dbpassword --database=dbname
SELECT `SERVER_ID`
FROM tc_services
WHERE `GAME_ID` LIKE '%TC510254610%'
INTO OUTFILE 'D:\\Program Files (x86)\\TCAdmin Control Panel\\ScheduledTasks\\GAME\\ServerID.txt'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n';
exit
Upvotes: 2
Views: 5365
Reputation: 44343
You have the files organized incorrectly. Please redo the file as follows:
@echo off
mysql --host=localhost --user=dbuser --password=dbpassword --database=dbname < script.sql
pause
SELECT `SERVER_ID`
FROM tc_services
WHERE `GAME_ID` LIKE '%TC510254610%'
INTO OUTFILE 'D:\\Program Files (x86)\\TCAdmin Control Panel\\ScheduledTasks\\GAME\\ServerID.txt'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n';
Upvotes: 1
Reputation: 1
You did not say what operating system you are using. It looks like you are trying to write your output file to the "\Program Files (x86)" directory. As a security measure Windows does not allow a user to write to that file area. You will need to go to the security settings of the "D:\Program Files (x86)\TCAdmin Control Panel\ScheduledTasks\GAME\" folder and make sure the user running the bat/script file has write access to that folder.
Upvotes: 0