connection to mysql


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting connection to mysql
# 1  
Old 06-17-2011
connection to mysql

is there some way i could connect to a remote mysql server from bash script
# 2  
Old 06-17-2011
Code:
 
#!/bin/sh  
   
uMYSQLConn="mysql -uUserName -pPassword -hhost_name_or_ip dbname"  
   
uMYSQLConn <<EOF   
select version();  
EOF

give the absolute path of mysql
# 3  
Old 06-17-2011
i need to connect to a remote mysql server..that means i should use ssh??

---------- Post updated at 12:37 PM ---------- Previous update was at 12:24 PM ----------

OK guys i got it

Code:
mysql --host=192.168.18.52 --user=user1 --password=User1 bugs

thanxxxSmilie
# 4  
Old 06-17-2011
try with isql

Code:
 
isql -s server-name -u username -p password

# 5  
Old 06-17-2011
now i am able to connect to remote mysql from my script,i am trying to execute
a query from the script,i tried it

Code:
`mysql --host=######## --user=####--password=###bugs<<SQL
$(select * from bugs);
quit
SQL`

but it outputs error

Code:
sh mysqlcon.sh 
mysqlcon.sh: command substitution: line 6: syntax error near unexpected token `from'
mysqlcon.sh: command substitution: line 6: `select \* from bugs'
release@buildserver IN [/release/releasescript] ON [Fri Jun 17 14:50:22]

pls help me in doin this

Last edited by born; 07-20-2011 at 06:24 AM..
# 6  
Old 06-17-2011
Code:
 
$(select * from bugs);
 
replace to
 
select * from bugs;

# 7  
Old 06-17-2011
thanxx dude....Smilie
i also tried the code


Code:
mysql --host=####### --user=#####--password=#####bugs < query.sql

query.sql contains the actual code...

Last edited by born; 07-20-2011 at 06:25 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run Shell Commands after creating MYSQL Connection

Hi, I am trying to make a Shell Script using which I will update around 10K records in MySQL db each night. For that, I am currently doing the following command in FOR LOOP: mysql -D $MASTER_DB_NAME -h $MASTER_DB_HOST -u $MASTER_DB_USER -p$MASTER_DB_PASSWD -e "$SQL_Query" This command is... (2 Replies)
Discussion started by: rahulmittal87
2 Replies

2. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

3. Linux

Unable to setup ODBC connection in RHEL5 64 bit and MySql 5.0

Hi , I am unable to setup ODBC connection in RHEL5 64 bit and MySql 5.0 I had modified ODBC.ini file , set the env variables such as LD_LIBRARY_PATH, ODBCINI , ODBCSYSINI etc . Getting the error as Data source name not found, and no default driver specified ERROR: Could not SQLConnect ... (0 Replies)
Discussion started by: roopalidalvi231
0 Replies

4. UNIX and Linux Applications

MySQL Daemon failed to start - no mysql.sock file

After doing a yum install mysql mysql-server on Fedora 14 I wasn't able to fully install the packages correctly. It installed MySQL 5.1. I was getting the following error when running the: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)... (3 Replies)
Discussion started by: jastanle84
3 Replies

5. Shell Programming and Scripting

Mysql command after a SSH connection (Script)

Hi all, Im new at scripting and i need to run a few commands at work every hours so i decide to make a script but on 1 of the steps i have a the follwoing problem: The command i do is this: #!/bin/bash ssh root@asdasd001 'mysql -h A-db-1 -uroot -password --execute "show slave status"'... (3 Replies)
Discussion started by: Aparicio
3 Replies

6. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

7. Cybersecurity

Open Port 3306 for MySQL connection

I am needing to "un-block" port 3306 so that I can access MySQL from another PC. When I installed Mandrake 8.1, I set the security level to high because it is going to be a web server. I believe I have to allow access to my ports now and I do not know the commands to do that. If anyone... (4 Replies)
Discussion started by: gdboling
4 Replies
Login or Register to Ask a Question