How to pass parameters to mysql

2019-05-19 20:51发布

During the installation I need to create new MySQL user, new database and populate it from dump file. My question is how can I do it from command line (cmd, Windows)? I mean, I'm calling for cmd from some script, which can start mysql command line client with root privileges but I cannot pass parameters to mysql form outside.

E.g. to create new user I'd like to run something like this:

cmd /c mysql -u root -p GRANT ALL ON *.* TO 'newuser'@'localhost' IDENTIFIED BY 'pass';

Is it possible? To pass *"GRANT ALL ON . TO 'newuser'@'localhost' IDENTIFIED BY 'pass';"* as parameter to mysql?

I hope I've made myself clear. Thanks in advance.

标签: cmd mysql
1条回答
冷血范
2楼-- · 2019-05-19 21:36

you need to add the -e parameter

cmd /c mysql -u root -p -e "GRANT ALL ON *.* TO 'newuser'@'localhost' IDENTIFIED BY 'pass'"
查看更多
登录 后发表回答