SQL and Rails

I just started reading the Manning Ruby for Rails guide and have no
prior experience with any of this material and I am stuck on
initializing an sql database. The book says it needs to be done for the
next step in the project, but I have no idea how to initialize the
database =/ or how to install it if that is even required.

Which OS are you using, which SQL DataBase are you using and version?

matt wrote:

Which OS are you using, which SQL DataBase are you using and version?

Using Gentoo and I don’t think I have mysql installed yet (not really
sure where to begin with it in relation to rails)

Well getting MySQL installed is paramount to getting things started.

I’m not a Gentoo user, but I use Fedora, so things should be similar
enough to get you started.

For MySQL Install, I use the yum package manager (yum install mysql*)

There are other package managers as well, apt-get, rpm’s, etc, if yum
isn’t your thing, let me know what works for you, maybe one of the
others on the list can chime in on getting you setup.

you can also check to see if it’s installed.

$ which mysql

or

$ yum list mysql*

If that returns something like /usr/bin/mysql then you’re in business.

You might want to check mysql.com they have a lot of good install
information as well.

I’ve been thinking about setting up a Gentoo box. It work well for you?

Matt

Excellent, with any luck we can get your db set up

you will need to make sure that the mysqld is running. On my system, I
run /etc/init.d/mysqld start

It basically runs through a script that makes a call
to /usr/bin/mysql-safe (or something like that) and sets up a mysqld
server daemon.

After the daemon is up and running,

$mysql -uroot

This will start your mysql session as root. Might have to use -p and a
password, but I believe that mysql defaults to a root user with no
password.

then you will get a mysql prompt.
then create 3 databases.
You can choose whatever you want, but by convention, the name of the
project followed by _development, _production and _test

mysql > create database db_development;
mysql > create database db_production;
mysql > create database db_test;

This will create the 3 databases that the book probably references. ( I
haven’t read that one, but the procedure should be the same)

then

mysql > grant all on db_development.* to ‘username’@‘localhost’
identified by ‘yourpassword’;

mysql > grant all on db_test.* to ‘username’@‘localhost’ identified by
‘yourpassword’;

you can do the same thing for the production db, but 2 things to
mentions. 1) while playing / developing, you may never use the
production db. 2) when using the production env, you want to cinch down
the permissions, so ‘grant all’ wouldn’t be appropriate. While
testing/developing, I grant all to my self on production, but never on
something that leaves my machine.

Also, ‘username’ is any name you choose
and ‘yourpassword’ is any password you choose.

All the while this has been as a root mysql user, so exit out of mysql
and log back in as such:

$ mysql -u username -p
enter password:

this will ask for your password you just set up.

mysql > show databases;

should display the 3 new databases we just setup

All should be good.

OK, I think that covers getting you set up from the command line.

I forgot that there are some GUI tools (mysql-admin, and another one…)
that makes it easier for some, but I’ve been command-line for so long,
that I forget about those things.

So let me know if this gets you setup with the DB

Matt

matt wrote:

So let me know if this gets you setup with the DB

Matt
perfect!! i think that is all i need for now, will probably pick this up
on thursday! thanks a mill matt and if you have any gentoo questions
feel free to ask!

matt wrote:

Well getting MySQL installed is paramount to getting things started.

I’m not a Gentoo user, but I use Fedora, so things should be similar
enough to get you started.

For MySQL Install, I use the yum package manager (yum install mysql*)

There are other package managers as well, apt-get, rpm’s, etc, if yum
isn’t your thing, let me know what works for you, maybe one of the
others on the list can chime in on getting you setup.

you can also check to see if it’s installed.

$ which mysql

or

$ yum list mysql*

If that returns something like /usr/bin/mysql then you’re in business.

You might want to check mysql.com they have a lot of good install
information as well.

I’ve been thinking about setting up a Gentoo box. It work well for you?

Matt

Love gentoo so far, dont have to deal with a bunch of extra trash that
other distros like to pack in with their installers and everything is
extremely configurable. Gentoo + Enlightenment DR17 is very nice.

Which mysql returned /usr/bin/mysql

so i know its installed now, what is next? any configuration needed?

Alexander Y. wrote:

matt wrote:

So let me know if this gets you setup with the DB

Matt
perfect!! i think that is all i need for now, will probably pick this up
on thursday! thanks a mill matt and if you have any gentoo questions
feel free to ask!

When I try to run the server and go to the demo the book provides i get
this error

Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

in your database.yml file, there is a section for development, test, and
production

in each section add the following:

socket: /var/lib/mysql/mysql.sock

That is the path that fedora uses, I suspect that it is the same on
Gentoo. There should be a way to find where the socket is located, but
I’m at a loss at the moment, so try the above first, and cross your
fingers.

Matt

matt wrote:

in your database.yml file, there is a section for development, test, and
production

in each section add the following:

socket: /var/lib/mysql/mysql.sock

That is the path that fedora uses, I suspect that it is the same on
Gentoo. There should be a way to find where the socket is located, but
I’m at a loss at the moment, so try the above first, and cross your
fingers.

Matt

no luck, even tried 'find’ing the file to no avail

Not for sure on what to say. Try to restart the mysqld daemon. Also
try the mysql forums, they might know more.

Google might get you over this hump too, but if I understand MySQL
correctly, a mysql.sock file gets created every time the daemon
re-starts, so I would try that first.

Good luck, you’re almost there.

Matt

matt wrote:

Not for sure on what to say. Try to restart the mysqld daemon. Also
try the mysql forums, they might know more.

Google might get you over this hump too, but if I understand MySQL
correctly, a mysql.sock file gets created every time the daemon
re-starts, so I would try that first.

Good luck, you’re almost there.

Matt

it seems to be magically working now after i restarted!

On 12/28/06, matt [email protected] wrote:

There should be a way to find where the socket is located

Sorry, late to the thread, but –

prompt% mysqld --print-defaults
mysqld would have been started with the following arguments:
–port=3306 --socket=/tmp/mysql.sock --default-character-set=utf8
–character_set_server=utf8 --datadir=/usr/local/mysql/data …

FWIW,

Hassan S. ------------------------ [email protected]