Editing a mySQL table on a remote machine


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Editing a mySQL table on a remote machine
# 1  
Old 10-10-2003
Editing a mySQL table on a remote machine

Hi all,

My problem: I want to connect to a remote computer (in the same office as me) which is running a mySQL server, access a specific table and update it, beofre disconnecting from the server. Is this possible? If so, any links/tutorials which might be of use?

I had thought of some sort of ssh to the machine and then embedded SQL in my shell script? Am I on the right track? I'm completely new to this sort of stuff so any help is appreciated.

TIA.
# 2  
Old 10-10-2003
Did you try to telnet to server and use the MySQL command line prompt?
# 3  
Old 10-10-2003
sorry, I forgot to mention, this should be done automatically when a condition is met in my shell script. This needs to be hardcoded in a shell script, not by manually telnet'ing the server.
# 4  
Old 10-10-2003
If you tell us the shell script language you are using it would
help us give you a specific example.

One idea would be to use ssh. In perl there is the module
use Net::SSH::Perl

then run MySQL command similar to this
$ssh->login(user, pass);
$ssh->cmd(update[table]);

I personaly would use PHP.

Have unix run the script automatically.
# 5  
Old 10-10-2003
I've only just started shelling, and don't really have any experience using perl or PHP. I'm going to try and 'build' my way up to the problem, as the learning curve for a lot of the problems my boss is giving me are quite steep.

I've simply started with:

mysql -h localhost -u unix_username -punix_password

which brings me into:

mysql>

From here I can 'toy around' in mysql, which I haven't done for a while. I think I should be able to replace the 'localhost' with the machine I am trying to connect to and take it from there.

Thanks for the replies, no doubt I'll run into problems over the next few days and be straight back in this forum! Where would I be without it!
# 6  
Old 10-13-2003
OK, avoiding the use of perl/PHP and simply scripting using the 'bash' shell, how can I execute MySQL commands?

Example script:
Code:
#!/bin/bash
# A simple script to create a small SQL table
#!/bin/bash

if ls -l | grep process
then
        mysql
        CREATE TABLE (......................);
        QUIT
else
        echo 0
fi

The above syntax does not work. Is there a way of 'embedding' MySQL syntax into a shell script? Is there something simliar to embedding Javascript into HTML (ie use of <--! ...... --> tags before and after the actual embedded script)? Also it would be very useful if I could insert variable values from the shell script into the MySQL table (eg if $1 has value 'dog' in the shell script, inserting the value 'dog' into a MySQL table automatically) Is this possible using the bash shell?

Any help appreciated.

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 03:06 PM..
# 7  
Old 10-14-2003
I think you are trying to kill elephant with fly swatter.

Bash may not be the right tool, but it would be interesting to see you get bash to manipulate MySQL.

Java, Perl, C/C++, PHP, Korn, python, etc., all have API's, but bash/born shell does not seem to have one.Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies

2. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

3. UNIX for Advanced & Expert Users

FTP While transfering files to local machine to remote machine

Hi Am using unix Ksh Am getting the problem while transferring zero size files through the script . When i transfer zero size files from local machine to remote machine manually i can able to do it . My question its beause of zero size files am not able to transfer through script ? or its... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

4. UNIX and Linux Applications

mysql table disappear

I have set a mysql file to excute everyday morning to generate a html file displayng 2 tables from the database. Sometime they cannot be shown, and it shows the tables are not existed. I have not drop any table, and those 2 tables are not used by any other excution. Anybody know what is happening?... (0 Replies)
Discussion started by: c203040
0 Replies

5. Solaris

Manually editing partition table

I'm manually editing the partition table purely for experimenting. I did prtvtoc /dev/dsk/c1t0d0s2 > /tmp/prtvtoc I'm trying to split up partition 5 to make partition 6. I'm running into a cylinder boundary error on partition 6. Any clues? # vi /tmp/prtvtoc "/tmp/prtvtoc" 23 lines, 769... (1 Reply)
Discussion started by: adelsin
1 Replies

6. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

7. Programming

API C MYSQL vs lock table ???

(sorry for my english) Hi, i have an app that uses MYSQL API C.. i trying do a timeout until the table is locked by an other thread , in the docs of Mysql i can see that MYSQL_OPT_READ_TIMEOUT is not implemented for linux ¿?¿?.. any body knows a way to do a timeout until the table is locked by... (0 Replies)
Discussion started by: JEscola
0 Replies

8. UNIX for Advanced & Expert Users

Editing MySQL config through ssh ?

I need a smal "how to" regarding editing mysql configuration on a unix server. Thanks in advance. (2 Replies)
Discussion started by: Denis.R
2 Replies

9. Shell Programming and Scripting

MySql: create table error

Hi, iam learning MySql. Iam trieing to create a table in the database "guestbook" at the command line in mysql heres what i type but i get a error mysql>create table guestbook ->( -> name varchar(40) null. -> url varchar(40) null. -> comments ... (3 Replies)
Discussion started by: perleo
3 Replies
Login or Register to Ask a Question