简体   繁体   中英

how can I pass database name from batch to mysql script

I am writing a Batch Script which takes list of credentials(dbname, ip, login, password) from a csv file and executes sql script using these values. I am able to do this in MS SQL Server but I am not able to pass these values dynamically in MYSQL.

Batch File:
Database name is set in %dbname%

mysql --host=%ip% --port=%port% --user=%user% --password=%pwd% --database=defaultdb < query.sql

query.sql:

select count(*) from x.test_table;

Instead of x, I want my database name from %dbname%

I think this question has been answered several times. Check this one for example:

Pass parameter from Batch file to MYSQL script

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM