批处理文件以连接mysql并运行命令 [英] Batch file to connect mysql and run commands

查看:559
本文介绍了批处理文件以连接mysql并运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Windows运行一个批处理文件,该Windows连接到另一台机器上的mysql服务器,并从数据库运行一个过程或运行一个位于我本地计算机上的sql文件.

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 machine.

有没有办法做到这一点.我知道我需要在批处理文件中使用以下脚本来运行sql命令,但我相信只有在mysql服务器环境中运行该批处理文件时,该脚本才有效.

is there's a way to do it. I know that I need the below script in my batch file to run sql commands but I believe it's only work when you run the batch file in mysql server enviornment.

我是否必须定义服务器信息(例如IP地址和端口) 我该怎么做

do I have to define the server info (e.g IP address & port) how do I do that

任何帮助都会被申请

谢谢

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

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

推荐答案

如果您的MySQL Server(mysqld)与MySQL客户端应用程序(

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

有效.

如果您的服务器位于另一台主机上(如您的情况),则必须添加主机名:

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

XXX.sql文件与MySQL客户端位于同一主机上.

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

在脱机状态下,您的服务器必须接受来自其他主机的连接(定义了绑定地址,没有跳过网络以及定义了正确的user @ host特权),因此请检查您的服务器配置.

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.

这篇关于批处理文件以连接mysql并运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆