Forum: Ruby MySQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Marcin T. (Guest)
on 2007-07-26 15:47
Hi,
 How to operate on MySQL? I would like to delete, create database and
upgrade with prepared files. I know mysql library but I'm not sure
whether it let me operate on  commands such as delete database, source
file_path etc.

I will be appreciated for any help

MT
Ronald F. (Guest)
on 2007-07-26 16:10
(Received via mailing list)
> I would like to delete, create database and
> upgrade with prepared files. I know mysql library but I'm not sure
> whether it let me operate on  commands such as delete database, source
> file_path etc.

If you connect with administrator privileges, you should be able
to execute any command you could also execute from the mysql
command line interface.

Ronald
Felix W. (Guest)
on 2007-07-26 16:14
(Received via mailing list)
> library but I'm not sure whether it let me operate on
> commands such as delete database, source file_path etc.
>
> I will be appreciated for any help
>
> MT
> --
> Posted via http://www.ruby-forum.com/.
>

Pretty much all database interfaces allow you to send raw commands.

Such as:

require "mysql"
dbh = Mysql.real_connect("localhost", "testuser", "testpass", "test")
dbh.query("CREATE TABLE test(column VARCHAR(255))")
dbh.query("DROP TABLE IF EXISTS test")
File.open("sql_commands_in_textfile") do |file|
  while line = file.gets
    dbh.query(line)
  end
end
Marcin T. (Guest)
on 2007-07-26 16:25
Ronald F. wrote:
>> I would like to delete, create database and
>> upgrade with prepared files. I know mysql library but I'm not sure
>> whether it let me operate on  commands such as delete database, source
>> file_path etc.
>
> If you connect with administrator privileges, you should be able
> to execute any command you could also execute from the mysql
> command line interface.
>
> Ronald

dbh.query("source c:/create.sql") - doesn't work. It causes SQL syntax.
Ronald F. (Guest)
on 2007-07-26 16:46
(Received via mailing list)
> dbh.query("source c:/create.sql") - doesn't work. It causes
> SQL syntax.

True, but for this case, you can always do

  IO.readlines("c:/create.sql").each { |s| dbh.query(s) }

Ronald
Marcin T. (Guest)
on 2007-07-26 16:51
Ronald F. wrote:
>> dbh.query("source c:/create.sql") - doesn't work. It causes
>> SQL syntax.
>
> True, but for this case, you can always do
>
>   IO.readlines("c:/create.sql").each { |s| dbh.query(s) }
>
> Ronald


Thanks, I'll check it. It seems to be ok. At the moment I cannot check
it (the db is used)
Felix W. (Guest)
on 2007-07-26 17:10
(Received via mailing list)
> >
> --
> Posted via http://www.ruby-forum.com/.
>


NEVER develop against a live database.
Ari B. (Guest)
on 2007-07-26 18:24
(Received via mailing list)
On Jul 26, 2007, at 7:47 AM, Marcin T. wrote:

> Hi,
>  How to operate on MySQL? I would like to delete, create database and
> upgrade with prepared files. I know mysql library but I'm not sure
> whether it let me operate on  commands such as delete database, source
> file_path etc.
>
> I will be appreciated for any help


You can use Ruby/MySQL, MySQL/Ruby, DBI, or ActiveRecord

~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.
John J. (Guest)
on 2007-07-29 08:33
(Received via mailing list)
On Jul 26, 2007, at 8:06 AM, Felix W. wrote:

>>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
>
> NEVER develop against a live database.
Safest advice, yes, but...
Well, you can, but that's when safety mechanisms like not developing
under root or not having all priveledges are good ideas.
It's their database though.
This topic is locked and can not be replied to.