tags:

views:

38

answers:

5

Can I run mysql delete row remotely from other machine? Something alike mysqldump which run locally dumping data on other remote machine.

+1  A: 

Only if you have TCP connections configured on the MySQL server, and you have a username and password configured that will allow you to remotely connect.

If you check the mysqldump documentation, you'll find the -host option allows you to connect to a remote system.

Phil Hayward
+1  A: 

You can try something like this:

mysql -u yourdblogin -pyourdbpassword -h yourdbdomain.yourdomain.com yourdb

Sorry if I misunderstood your question.

Jorge Israel Peña
A: 

The specific way of doing this is to connect to the remote machine using the mysql prompt and then execute queries against it (queries which cause a row to be deleted.)

# mysql -u username -p -h remote.location.com
mysql> USE `database_name`;
mysql> DELETE FROM `table` WHERE id=1234;

The DELETE FROM syntax is SQL syntax, and the WHERE part of it allows you to specific exactly what you want to be deleted.

Also, you most likely won't be able to log in as 'root' if you're used to doing so, as root by default can't connect remotely. (You can enable this, but it's recommended instead to make another admin account and to use that instead).

Note that code may also remotely delete rows, however it depends on the language and implementation as to how it's done.

References:

T. Stone
can i do that in 1 line? as i want to run it with cron
conandor
You could do that (someone else posted a long command), but it would probably make more sense to write a small script in python/perl/ruby instead as you can add error handling or logging to let you know if it fails.
T. Stone
A: 

You can actually use any MySQL client application to connect to remote servers, not only the supplied command-line tool.

If the server allows TCP client connections, there are no differences between running scripts locally or remotely.

If the MySQL server happens to be also a web server, you can use a software like PHPMyAdmin to do it. Once it runs locally (on the same machine as the MySQL server, not your machine), you can work around the problem of not accepting external TCP connections, if the server was configured that way.

Doug
+1  A: 

try:

mysql -u yourdblogin -pyourdbpassword -h yourdbdomain.yourdomain.com yourdb -e "delete from table where x = y"

not sure if -e is the correct argument, but the though is sound.

Nathan Feger
Yes. This is what I looking for. mysql -h myserver.net -umyname -pmypw mydb -e "select * from mytable"
conandor