Changing from database sqlite3 to mysql - windows

Hi Guys

I'd like to know how to change from using sqlite3 to mysql. I'm running windows xp. What is the command that I must type under my application folder? How to I log into the mysql database afterwards?

My database.yml file contents at the moment are: # SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development:   adapter: sqlite3   database: db/development.sqlite3   pool: 5   timeout: 5000

# Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test:   adapter: sqlite3   database: db/test.sqlite3   pool: 5   timeout: 5000

production:   adapter: sqlite3   database: db/production.sqlite3   pool: 5   timeout: 5000

Thanks in advance.

Wal T

Hi Guys

I'd like to know how to change from using sqlite3 to mysql. I'm running windows xp. What is the command that I must type under my application folder? How to I log into the mysql database afterwards?

Assuming you have MySQL Community Server for Windows installed already (if not, go to mysql.com to download it), then change your database.yml sections to look like this, for example:

development:   adapter: mysql   encoding: utf8   reconnect: false   database: hockey_development   pool: 5   username: root   password:   host: localhost

Of course you want to change the database name, username, and password as needed (use the same username and password as you did when you installed the mysql server).

And for future rails apps, you can have rails build this for automatically:

C:\dev> rails myapp -d mysql

Hope this helps?

Jeff

book: Rails for .NET Developers: www.pragprog.com/titles/cerailn blog: softiesonrails.com web: purpleworkshops.com

Hi Jeff

Thanks for your reply.

Yes I installed the MySQL Community Server for Windows.

I'm still struggling to check if mysql is installed for ruby.

I installed mysql in the g:\program files\mysql directory & ruby on rails is installed in the g:\ruby directory. I'm running my music_library app in the g:\rails\rails_apps\music_library directory.

Now the updated database.yml file says:

On Windows: # gem install mysql # Choose the win32 build. # Install MySQL and put its /bin directory on your path.

So I tried this command: G:\Rails\rails_apps>gem install mysql

and I get: Successfully installed mysql-2.7.3-x86-mswin32 1 gem installed Installing ri documentation for mysql-2.7.3-x86-mswin32... Installing RDoc documentation for mysql-2.7.3-x86-mswin32... ERROR: While generating documentation for mysql-2.7.3-x86-mswin32 ... MESSAGE: Unhandled special: Special: type=17, text="<!-- $Id: README.html, v 1.20 2006-12-20 05:31:52 tommy Exp $ -->" ... RDOC args: --op g:/Ruby/lib/ruby/gems/1.8/doc/mysql-2.7.3-x86- mswin32/rdoc - -exclude ext --main README --quiet ext README docs/README.html (continuing with the rest of the installation)

I'm not sure what it means by "put its /bin directory on your path" and I tried to copy the bin directory from the G:\Program Files\MySQL \MySQL Server 5.1 directory to the G:\Rails\rails_apps\music_library directory and run the following command to check if mysql is running ok:

G:\Rails\rails_apps>mysql -v and I get the error: 'mysql' is not recognized as an internal or external command, operable program or batch file.

Please help - where am I going wrong?

Thanks

Wal T

I'm not sure what it means by "put its /bin directory on your path" and I tried to copy the bin directory from the G:\Program Files\MySQL \MySQL Server 5.1 directory to the G:\Rails\rails_apps\music_library directory and run the following command to check if mysql is running ok:

G:\Rails\rails_apps>mysql -v and I get the error: 'mysql' is not recognized as an internal or external command, operable program or batch file.

Somewhere inside the mysql directory there is a folder called bin with the mysql command line utility and various DLLs. That comment is telling you to add that path to the environment variable called PATH (which has the effect that windows will look in that folder when it tries to find what application it should run when you type mysql) If my windows memory is correct you can edit environment variables from somewhere in the control panel.

Fred

Somewhere inside the mysql directory

Do you mean mysql folder under G:\Rails\rails_apps\music_library? This is where I'm running my music_library application.

That comment is

telling you to add that path to the environment variable called PATH

I don't understand what you are saying here. Sorry I'm new to RoR.

OK I've tried:

G:\Rails\rails_apps\music_library>ruby mysql -v (since I noticed on windows one has to type 'ruby' first to run some commands.

and I get: ruby: Permission denied -- mysql (LoadError)

WalT wrote:

Somewhere inside the mysql directory

Do you mean mysql folder under G:\Rails\rails_apps\music_library? This is where I'm running my music_library application.

No, he means the directory where mySQL is installed.

That comment is

telling you to add that path to the environment variable called PATH

I don't understand what you are saying here. Sorry I'm new to RoR.

This has nothing to do with Rails. It's a basic Windows (and Un*x) concept. Go learn about it; this is elementary and you need to know.

OK I've tried:

G:\Rails\rails_apps\music_library>ruby mysql -v (since I noticed on windows one has to type 'ruby' first to run some commands.

and I get: ruby: Permission denied -- mysql (LoadError)

That won't help. The mySQL server is not a Ruby script.

(But in my opinion, you shouldn't use mySQL. PostgreSQL is a much better database server. For most projects, there is no reason at all to even consider mySQL.)

Best,

No, he means the directory where mySQL is installed.

I mentioned above that there's a bin folder in the directory where mysql is installed: G:\Program Files\MySQL \MySQL Server 5.1.

That comment is

>> telling you to add that path to the environment variable called PATH

> I don't understand what you are saying here. Sorry I'm new to RoR.

This has nothing to do with Rails. It's a basic Windows (and Un*x) concept. Go learn about it; this is elementary and you need to know.

I disagree - this is not a windows concept. It's a ruby concept. Can someone else please help me to use mysql with ruby? I can see that under directory G:\Rails\rails_apps\music_library\config there's a file called environment.rb and its contents are:

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|   # Settings in config/environments/* take precedence over those specified here.   # Application configuration should go into files in config/ initializers   # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs   # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install   # config.gem "bj"   # config.gem "hpricot", :version => '0.6', :source => "http:// code.whytheluckystiff.net"   # config.gem "sqlite3-ruby", :lib => "sqlite3"   # config.gem "aws-s3", :lib => "aws/s3"

  # Only load the plugins named here, in the order given (default is alphabetical).   # :all can be used as a placeholder for all plugins not explicitly named   # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,   # you must remove the Active Record framework.   # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running   # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.   # Run "rake -D time" for a list of tasks for finding time zone names.   config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/ *.rb,yml are auto loaded.   # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*. {rb,yml}')]   # config.i18n.default_locale = :de end

Please guys I already know how to use mysql syntax to "talk" to a database, I just don't know how to "tell" ruby to use mysql instead of sqlite3.

Thanks

That comment is

>> telling you to add that path to the environment variable called PATH

> I don't understand what you are saying here. Sorry I'm new to RoR.

This has nothing to do with Rails. It's a basic Windows (and Un*x) concept. Go learn about it; this is elementary and you need to know.

I disagree - this is not a windows concept. It's a ruby concept.

Then you are spectacularly wrong. Setting the proper value to your PATH variable is a basic task for anyone who intends to program.

someone else please help me to use mysql with ruby? I can see that under directory G:\Rails\rails_apps\music_library\config there's a file called environment.rb and its contents are:

irrelevant. As you've already been told, config/database.yml is the file with your database settings.

Why keep asking if you're not going to take any advice? :slight_smile:

No, he means the directory where mySQL is installed.

I mentioned above that there's a bin folder in the directory where mysql is installed: G:\Program Files\MySQL \MySQL Server 5.1.

That comment is

>> telling you to add that path to the environment variable called PATH

> I don't understand what you are saying here. Sorry I'm new to RoR.

This has nothing to do with Rails. It's a basic Windows (and Un*x) concept. Go learn about it; this is elementary and you need to know.

I disagree - this is not a windows concept. It's a ruby concept. Can someone else please help me to use mysql with ruby? I can see that under directory G:\Rails\rails_apps\music_library\config there's a file called environment.rb and its contents are:

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|   # Settings in config/environments/* take precedence over those specified here.   # Application configuration should go into files in config/ initializers   # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs   # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install   # config.gem "bj"   # config.gem "hpricot", :version => '0.6', :source => "http:// code.whytheluckystiff.net"   # config.gem "sqlite3-ruby", :lib => "sqlite3"   # config.gem "aws-s3", :lib => "aws/s3"

  # Only load the plugins named here, in the order given (default is alphabetical).   # :all can be used as a placeholder for all plugins not explicitly named   # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,   # you must remove the Active Record framework.   # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running   # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.   # Run "rake -D time" for a list of tasks for finding time zone names.   config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/ *.rb,yml are auto loaded.   # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*. {rb,yml}')]   # config.i18n.default_locale = :de end

Please guys I already know how to use mysql syntax to "talk" to a database, I just don't know how to "tell" ruby to use mysql instead of sqlite3.

Thanks

Then you are spectacularly wrong. Setting the proper value to your

PATH variable is a basic task for anyone who intends to program.

Why keep asking if you're not going to take any advice? :slight_smile:

I can only take the right advise... I took Jeff's advise to change the database.yml file.

What OS are you using? Under windows, under control panel, there's no path variable setting. If there is, please tell me where? I'm a web developer and not a programmer :wink:

As you've already been told, config/database.yml is the

file with your database settings.

I have already changed my database.yml file as follows, as per Jeff's advise:

# MySQL. Versions 4.1 and 5.0 are recommended.

Then you are spectacularly wrong. Setting the proper value to your

PATH variable is a basic task for anyone who intends to program.

Why keep asking if you're not going to take any advice? :slight_smile:

I can only take the right advise... I took Jeff's advise to change the database.yml file.

What OS are you using? Under windows, under control panel, there's no path variable setting. If there is, please tell me where? I'm a web developer and not a programmer :wink:

As you've already been told, config/database.yml is the

file with your database settings.

I have already changed my database.yml file as follows, as per Jeff's advise:

# MySQL. Versions 4.1 and 5.0 are recommended.

Then you are spectacularly wrong. Setting the proper value to your

PATH variable is a basic task for anyone who intends to program.

Why keep asking if you're not going to take any advice? :slight_smile:

I can only take the right advise... I took Jeff's advise to change the database.yml file.

What OS are you using? Under windows, under control panel, there's no path variable setting. If there is, please tell me where? I'm a web developer and not a programmer :wink:

As you've already been told, config/database.yml is the

file with your database settings.

I have already changed my database.yml file as follows, as per Jeff's advise:

# MySQL. Versions 4.1 and 5.0 are recommended.

Then you are spectacularly wrong. Setting the proper value to your

PATH variable is a basic task for anyone who intends to program.

Why keep asking if you're not going to take any advice? :slight_smile:

I can only take the right advise... I took Jeff's advise to change the database.yml file.

What OS are you using? Under windows, under control panel, there's no path variable setting. If there is, please tell me where? I'm a web developer and not a programmer :wink:

As you've already been told, config/database.yml is the

file with your database settings.

I have already changed my database.yml file as follows, as per Jeff's advise:

# MySQL. Versions 4.1 and 5.0 are recommended.

Then you are spectacularly wrong. Setting the proper value to your

PATH variable is a basic task for anyone who intends to program.

Why keep asking if you're not going to take any advice? :slight_smile:

I can only take the right advise... I took Jeff's advise to change the database.yml file.

What OS are you using? Under windows, under control panel, there's no path variable setting. If there is, please tell me where? I'm a web developer and not a programmer :wink:

As you've already been told, config/database.yml is the

file with your database settings.

I have already changed my database.yml file as follows, as per Jeff's advise:

# MySQL. Versions 4.1 and 5.0 are recommended.

Then you are spectacularly wrong. Setting the proper value to your

PATH variable is a basic task for anyone who intends to program.

Why keep asking if you're not going to take any advice? :slight_smile:

I can only take the right advise... I took Jeff's advise to change the database.yml file.

What OS are you using? Under windows, under control panel, there's no path variable setting. If there is, please tell me where? I'm a web developer and not a programmer :wink:

As you've already been told, config/database.yml is the

file with your database settings.

I have already changed my database.yml file as follows, as per Jeff's advise:

# MySQL. Versions 4.1 and 5.0 are recommended.

Au contraire -- google `set windows PATH` for lots of instructions.

I'll try again....

Walt, when you say that this happened:

G:\Rails\rails_apps>mysql -v and I get the error: 'mysql' is not recognized as an internal or external command, operable program or batch file.

then it means that Windows is telling you that it can't find the "mysql" program, right?

And if that's true, then Ruby also has no way to talk to mysql either. Hence all the advice about making sure that the mysql.exe is in your PATH. If you're not sure how to find mysql.exe or adjust your PATH, you'll need to ask for basic Windows help, which is beyond the scope of this forum

However, assuming this all makes sense to you now, I'd suggest:

1. Adjust your PATH so that you can successfully run "mysql -v" 2. Re-installing the mysql gem: hopefully now it can find the mysql.exe binary in your path

Does that make sense?

Thanks Jeff

purpleworkshops.com softiesonrails.com pragprog.com/titles/cerailn

To all the guys using Windows OS and want to use mysql as your database:

I went around all the forums of ruby that I could find on the internet and I'm glad I got the answer that I was looking for:

The path that I was looking for was G:\Ruby\bin. Ignore the wording 'add that path to the environment variable called PATH' cos it's just not in laymen's term for me.

All I needed to do was to copy the files from G:\Rails\mysql\bin directory (windows explorer) to the directory G:\Ruby\bin as they are. I had to look for the file libmySQL.dll from google and download it as this was missing when I installed mysql from the command 'gem install mysql'.

I copied all the files including mysql.exe, mysqladmin.exe and libmySQL.dll to the directory G:\Ruby\bin. These files are also available from the directory where you installed mysql on its own.

Then I tried again the command mysql -v and I got ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

Now I knew I was close to solving the problem, so I knew it is the logging in issue that's left to be solved. so I typed in

mysql -u root --password=*** music_library_development and I got: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 15 to server version: 5.1.36-community

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

Hooray!

Thanks to all the guys that helped in this forum - just bear in mind that some of us are beginners and do not know all the ruby terms so we need plain old English to survive :wink:

WalT wrote:

To all the guys using Windows OS and want to use mysql as your database:

I went around all the forums of ruby that I could find on the internet and I'm glad I got the answer that I was looking for:

The path that I was looking for was G:\Ruby\bin. Ignore the wording 'add that path to the environment variable called PATH' cos it's just not in laymen's term for me.

You're a programmer now, not a layman. There are things you must learn, and as Hassan and I have both advised you, *one of the things you must learn is what your PATH is*. Do not ignore it. Learn to deal with it properly.

All I needed to do was to copy the files from G:\Rails\mysql\bin directory (windows explorer) to the directory G:\Ruby\bin as they are.

No! While this kind of works in this particular case, it is a *very bad* idea: you now have your mySQL binaries mixed up with your Ruby binaries. God help you.

And it didn't have to be this way: if you'd actually taken the advice several of us were giving you, you could have done it right.

[...]

Thanks to all the guys that helped in this forum - just bear in mind that some of us are beginners and do not know all the ruby terms so we need plain old English to survive :wink:

For the third time: *this had nothing to do with Ruby concepts*. If you can't be bothered to learn what your PATH environment variable is (nothing to do with Ruby) and how to set it (nothing to do with Ruby), then (a) you will most likely screw up your system (as you've done with your supposed "fix" here) and (b) you have no business trying to program.

I hate to be that harsh, but that's the way it is. As a programmer, you have great power, and you *must* learn to do things correctly so that you can use that power responsibly. If you're not willing to take 5 minutes to learn about a rudimentary OS concept such as the PATH, then you're not ready for the power that programming provides. For your own sake, stop before you completely screw up your system.

Best,

My system is perfectly fine, and everything works smoothly & I'm smooth sailing getting even deeper into Ruby! I'm even going to read & watch all the Ruby on Rails books/tutorials that I can find including lynda.com.

If you can't explain something to an old lady then you don't understand it. Plain & simple. And no, like I said before I'm not a programmer, I'm a web developer. Proud to be a layman! I actually like Ruby cos its syntax is more like plain old English!

Like I said before, I cannot take wrong advice. Not all advice is good advice... One must learn to separate the good from the bad. I took the advise that led me to the right direction, and ignored the other advice which wasn't helpful to me. That's my call to make, not yours.

I found the solution (and not a shortcut) to my problem and that's what counts - nothing you say will change anything.

You can stay being a programmer and talk your programming jargon which you don't even understand half of it, if that turns you on - that's your choice, not mine.

Now, let me get on with my happy learning and stop wasting my time replying to you. I'm done with my chat here (or, should I say 'terminated my electronic conversation')...