MySQL


#1

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


#2

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


#3

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


#4

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.


#5

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


#6


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

NEVER develop against a live database.


#7

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.


#8

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.


#9

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)