Batch file to connect mysql and run commands

后端 未结 3 390
闹比i
闹比i 2021-01-24 05:47

I want to run a batch file from windows, which connect to mysql server on different machine, and run a procedure from database or run a sql file which is sitting in my local mac

3条回答
  •  一生所求
    2021-01-24 06:15

    if your MySQL Server (mysqld) is running on the same host as your MySQL client application (mysql), your command

    mysql --user=XXX --password=XXXX --database=XXX < XXX.sql
    

    works.

    If your server is on another host (as in your case), you have to add the hostname:

    mysql --host=IP.ADDR.HERE --port=3306 --user=XXX --password=XXXX --database=XXX < XXX.sql
    

    The XXX.sql file is on the same host as your MySQL Client.

    Offcourse your server has to accept connections from other hosts (bind-address defined, no skip-networking, and the correct user@host privileges defined) so check your server configuration.

提交回复
热议问题