how to connect to mysql using shell script

Hi,
please let me know
how to connect to mysql using shell script?
when i run shell script ,it should connect to mysql DB
rgds
vijji
vijji_lakshmiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
UmeshConnect With a Mentor MySQL Principle Technical Support EngineerCommented:
This works..

Replace

"select version();" with actual queries...
UserName - with mysql User name

pPassword -WIth password
host_name_or_ip - with host name
dbname - with DBNAME

Also, its good to pass complete path to 'mysql' utility

#!/bin/sh
 
uMYSQLConn="mysql -uUserName -pPassword -hhost_name_or_ip dbname"
 
uMYSQLConn <<EOF 
select version();
EOF

Open in new window

0
 
UmeshMySQL Principle Technical Support EngineerCommented:
Which shell???
0
 
vijji_lakshmiAuthor Commented:
we are using red hat linux 5.0
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can use the mysql command line tool:
http://dev.mysql.com/doc/refman/5.0/en/mysql.html
0
All Courses

From novice to tech pro — start learning today.