Command Line tool to run SQL statements?

Soldato
Joined
31 May 2006
Posts
4,239
Location
127.0.0.1
Hi all

I was wondering if there is a tool (which runs on Windows XP) where you can run it like the following:

mysqltool "SELECT * FROM table1" /u:myuser /p:my password /d:mydatabase /s:server.local (or ip address)

or an UPDATE, or INSERT etc....

And it return the result in the command window. I want to be able to run this command from any workstation and it not require anything to be installed (so the tol can run from the machine or a network drive etc...) and can be run as part of a windows batch file.

I created my own app that did this in VB .Net but it needed the MySQL ODBC driver installing on the client machine which I could do without really.

Any ideas?

Thanks
 
Hi,

This might be overkill.... but one way you could do this would be to write it as a servlet running on a server. The servlet would receive a request from the PC specifying the database, SQL statement, and any other flags. It would then connect to the required database, run the SQL and send the response back to the front-end.

Using this approach you wouldn't need anything installed on the PC, and could easily configure things so that different databases could be connected to as required with no impact on the client machines.

The above has Java in mind but you could also do such a thing using Perl etc.

As I said, could be more than what you need, but such a servlet/process wouldn't be hard to write and would be pretty flexible.

Jim
 
erm, mysql comes with the mysql.exe cli tool, even on windows.

mysql.exe -u username --password yourpass databasename -e "SELECT fields FROM table;"

or for several queries at once, stick them in a file and do

mysql.exe -u username --password yourpass databasename < file.sql
 
ultamately you will need to install some sort of driver/odbc and possibly a client app of some sort, regardless of RDBMS. you need these so that the computer knows where to connect to and how to make the connection.

so yes you can run this via a cmd prompt. But you will need to have installed at least the mysql client software on the computer to enable the connection or the odbc/drivers required.

The alternative is to as stated, create a web-page (using PHP/JAVA ServerPages/etc) for users to use as a SQL Prompt interface (google iSQL*PLUS which is what Oracle 10g uses)
 
er..
windows key+r > 'cmd' > enter; in the resulting command prompt:
Code:
mysql
and hit enter..

He doesn't want to install anything locally though. Remember that MySQL is running as a web service (on port 3306 by default) like the webserver so if it's configured to allow external connections then you can login to it via a shell (such as ssh). This would also allow you to put commands into a batch file.
 
Last edited:
Back
Top Bottom