Because the vertical output mode of the mysql command is very nice, I've setup my environment to default the output to vertical layout. I've done this by creating c:\windows\my.cnf that contains
[mysql]
vertical
Regrettably, all my mysql shell scripts also pick up on this setting, wreaking havoc with parsing the output of the mysql command.
Is there command-line switch or SQL I can use to override the vertical setting in my.cnf when invoking mysql from a shell script?
Specifically, I have a shell script that looks something like this
set SQLFILE=.\cmdelOldRecords.sql
set TMPCKTFILE=.\temp2.sql
:: get all "_aud" tables from database
mysql -h %1 --port=3306 --dat开发者_开发百科abase=%MYSQL_DB% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% -B -N -e "show tables like '%%\_aud'" > %TMPCKTFILE%
for /F "tokens=1" %%i in ('type %TMPCKTFILE%') do (
echo drop table %%i; >> %SQLFILE%
echo commit; >> %SQLFILE%
)
mysql -h %1 --port=3306 --database=%MYSQL_DB% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% -B -N < %SQLFILE%
But my .\cmdelOldRecords.sql ends up with stuff like
drop table ***************************;
there is the -E (or --vertical) switch to get the client act vertical this means you could try:
mysql --vertical=false
You can have your client overide the options of my.cnf by having a ~/.my.cnf file.
I am not sure that all options can be overriden, reading the man page I posted and/or experimenting will tell you.
精彩评论