Call command line MySQL with user and password

2 次查看(过去 30 天)
Hi,
I'm trying to call MySQL from Matlab in the same way you can call it from the DOS command line, i.e. (without the quotation marks)
"mysql -utestuser -ptestpass < query.txt > output.txt"
This syntax works in a DOS command prompt, but when I use the same command with the system() function in Matlab, so
system('mysql -utestuser -ptestpass < query.txt > output.txt')
I get "error 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: NO)".
It looks like the password isn't passed to the mysql command properly. I've tried a couple of different combinations of single and double quotation marks, but none seem to work. Do you know if it's possible to pass a MySQL command like this from Matlab and if so what the exact syntax should be?
I cannot get the ODBC driver installed on this machine, which is why I'm trying to do it in this way
Thanks!
Joe

采纳的回答

Jos
Jos 2014-7-18
Found the solution myself, might be helpful for someone else, write the mysql command to a batch file (e.g. test.bat) and call the batch file using the system command, system('test.bat'). This works around the formatting issues

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by