Windows cmd connect to remote mysql dbf

Is there a way to connect to mysql dbf on remote server and run sql queries using windows command line?


source to share

4 answers

MySQL has a command line client where you can run queries. If you don't want to allow remote connections to the database on the server, you can still script things into a batch. There are telnet / ssh clients from the command line that either accept an external file as a list of commands to run remotely, or you can pass it with input redirection (less than a character).

When opening a connection to the server, most clients are programmed so that the only way to specify a login password is to enter it from the keyboard (yes, they don't use the default input stream). Such things make it difficult for him. However, it may be possible to configure certificate-based login on SSH - you really need to investigate this.

If the server that hosts the MySQL database is also a web server, you might also consider putting a password protected script area (PHP, Perl, Python, Ruby - whatever you like), which will allow you to making requests with a simple HTTP (S) request on this script. Although there is no command line HTTP (S) client on Windows, you can always grab something like wget.exe and run queries with it. Note that if you choose this approach, I highly recommend putting this script under HTTPS - if detected by an attacker, it could be fatal to your data.



Yes, you can connect to a different host by running mysql -h . Note that there are several security implications:

  • You will have to grant yourself access. You need to run something like GRANT ALL on db_name.table TO user@your_ip IDENTIFIED BY 'password'

    . db_name

    , table

    and your_ip

    maybe *

    , but beware of opening your server up to hackers.
  • You will have to open the server firewall if you are not on the same local network. Again, ymmv and you should know not to open the door to exploits.
  • You can use SSL and use secure-auth to protect your traffic and credentials.

Hope it helps.



You can use telnet or SSH if you want to be more secure.



If MySQL is running Linux or BSD you need Telnet or SSH connection through something like putty

This will open a command prompt on the remote server. Mysql command . There will be problems with authenticating remote users (as you would expect).

If the remote server is running Windows, you have a number of problems.

I'm not sure if you can connect to a remote windows server and control it that way.

I have to say that I'm not sure HOW you could connect to a remote windows server and use it that way. But no doubt it is possible.



All Articles