Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > mysql source command doesn't work?

Reply
Thread Tools

mysql source command doesn't work?

 
 
Raymond O'connor
Guest
Posts: n/a
 
      12-02-2006
I'm trying to use the mysql 'source' command within a ruby script to run
a batch file, but it doens't seem to work. When I run the source
command straight from mysql, though, it runs just fine. Here's a short
example of what I'm trying to do:

require 'mysql'
db = Mysql.real_connect(db_host, db_user, db_pass, db_name)
filename = "/Users/test/batch.sql"
db.query "source #{filename}"


I keep getting this error when I try to do dbh.query "source
${filename}"

Error code: 1064
Error message: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'SOURCE /Users/test/batch.sql' at line 1
Error SQLSTATE: 42000


Anyone have any ideas? Thanks in advance.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Park Heesob
Guest
Posts: n/a
 
      12-02-2006

Hi,

>From: Raymond O'connor <(E-Mail Removed)>
>Reply-To: http://www.velocityreviews.com/forums/(E-Mail Removed)
>To: (E-Mail Removed) (ruby-talk ML)
>Subject: mysql source command doesn't work?
>Date: Sat, 2 Dec 2006 10:21:49 +0900
>
>I'm trying to use the mysql 'source' command within a ruby script to run
>a batch file, but it doens't seem to work. When I run the source
>command straight from mysql, though, it runs just fine. Here's a short
>example of what I'm trying to do:
>
>require 'mysql'
>db = Mysql.real_connect(db_host, db_user, db_pass, db_name)
>filename = "/Users/test/batch.sql"
>db.query "source #{filename}"
>
>
>I keep getting this error when I try to do dbh.query "source
>${filename}"
>
>Error code: 1064
>Error message: You have an error in your SQL syntax; check the manual
>that corresponds to your MySQL server version for the right syntax to
>use near 'SOURCE /Users/test/batch.sql' at line 1
>Error SQLSTATE: 42000
>
>
>Anyone have any ideas? Thanks in advance.
>


'source' is not an SQL command, but an internal command of the mysql command
line client.

You could use Ruby's system like this:

system("/path/to/mysql -uuser -ppassword database <#{filename}");

Regards,

Park Heesob

__________________________________________________ _______________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/g...ave/direct/01/


 
Reply With Quote
 
 
 
 
David Vallner
Guest
Posts: n/a
 
      12-02-2006
--------------enigC2D64F734A2CC3FD45B7EE52
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Park Heesob wrote:
>> I'm trying to use the mysql 'source' command within a ruby script to r=

un
>> a batch file, but it doens't seem to work. When I run the source
>> command straight from mysql, though, it runs just fine. Here's a shor=

t
>> example of what I'm trying to do:
>>
>> Anyone have any ideas? Thanks in advance.
>>

>=20
> 'source' is not an SQL command, but an internal command of the mysql
> command line client.
>=20
> You could use Ruby's system like this:
>=20
> system("/path/to/mysql -uuser -ppassword database <#{filename}");
>=20


That presumes the ruby script and the SQL script are colocated (and this
being MySQL, if my assumptions on users of that product hold, the
database server will also be on the same machine).

In that case, you can also read the file inside the Ruby process and
then feed the commands to the database connection. This has the
advantage that you don't show your DB username and password to all and
sundry connected to that machine in ps output. (Passwords on command
lines are bad, 'mmmkay.)

David Vallner


--------------enigC2D64F734A2CC3FD45B7EE52
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFcWMIy6MhrS8astoRApbKAJ4ojQtBDTeCBWULi8RLOW scGhyKIQCggGu1
/I34RqZwxSRLs36FlIHLhIg=
=GrKF
-----END PGP SIGNATURE-----

--------------enigC2D64F734A2CC3FD45B7EE52--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why in perl system(" ") command, "source command_file" does nothing,but "source command_file && echo" works? Kuhl Perl Misc 1 12-22-2008 02:29 PM
MySQL-python-1.2.2 install with no mysql washakie Python 4 01-15-2008 08:15 PM
"mysql.h: No such file or directory" when building MySQL-python francescomoi@europe.com Python 2 05-11-2005 03:12 PM
DBD:mysql doesn't read mysql option file /etc/my.cnf file JL Perl 0 01-28-2005 03:19 AM
"Pure Python" MySQL module like Net::MySQL Ravi Python 6 07-21-2003 06:53 PM



Advertisments