# Arather basic and rather stupid MySQL question

**URL:** <https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195>\
**Category:** Rails\
**Created:** [August 3, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195 "2007-08-03T18:52:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 3, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195/1 "2007-08-03T18:52:35Z")

</div>

Email : removed\_email\_address@domain.invalid

If I can do it then it can’t be done ! … - Anonymous

As Dr. Nick of the Simpsons sez :

Hi Everybody !

I’m trying to use Patrick Lenz’ Site Point book entitled “Build Your  
Own Ruby on Rails Web Applications” as a guide for my 1st Ruby on  
Rails project.

> From here on in I’m going to refer to this book as : “BYORORWA”.

Unfortunately, I’m stuck on Chapter 2 “Getting Started”.

I’m working on a 1.8 GHz Mac running under Mac OSX 10.4.10 .  
According to “About This Mac” , “More Info …” the specific  
microprocessor my machine has is a : "CPU Type: PowerPC 970 (2.2)

I actually gave up on the instructions for installing the Ruby on  
Rails development environment for Mac OSX given on pages 24 to 31 as I  
simply couldn’t get them to work.

I then switched over to trying to install my Ruby on Rails development  
environment on Mac OSX using the HiveLogic article entitled “Building  
Ruby, Rails, Subversion, Mongrel, and MySQL on Mac OS X” by Dan  
Benjamin. The earl for this article is located at :

[Dan Benjamin](http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx)

I’m reasonably sure that I’ve correctly installed everything because  
if I do the following :

1. Open up a Terminal window.
2. Enter the command “cd cyf” to change the directory to the RoR  
project I’ve created (which is called “cyf”).
3. Enter the command “script/server” to start up the Mongrel web  
server for this project.
4. Fire up the Safari application.
5. Enter the earl “[http://localhost:3000/](http://localhost:3000/)” in the earl display/input  
field at the top of the Safari application.
6. Click on the “About your application’s environment” earl in the  
“Welcome Aboard”  
page that typing in the previous step brings up.

I get the following text displayed in a yellow box :

Ruby version : 1.8.6 (powerpc-darwin8.10.0)  
RubyGems version : 0.9.2  
Rails version : 1.2.3  
Active Record version : 1.15.3  
Action Pack version : 1.13.3  
Active Web Service version : 1.2.3  
Action Mailer version : 1.3.3  
Active Support version : 1.4.2  
Application root version : /Users/simonwhelan/cyf  
Environment version : development  
Database adapter version : mysql

My problem ?

Well, I believe my problem is 2 fold; i.e. :

1. It looks to me as though the MySQL client is not able to connect to  
the MySQL server.
2. I’m too ignorant and inexperienced to be sure that I’m doing things  
properly and I don’t know how to properly interpret the diagnostics  
I’m getting much less fix the problems I think I’m having.

I should point out here that I’ve successfully installed the MySQL  
System Preferences panel.

It is set to “Automatically Start MySQL Server on Startup”.

When I bring up the MySQL System Preferences panel to have a look, it  
sez : “The MySQL Server Instance is running”. The string “running” is  
display in a rather attractive lime green color.

It looks to me like I’ve successfully installed MySQL 5.0.45-osx10.4  
in the directory “/usr/local/mysql”.

If I ‘cd’ to that directory and enter ‘ls’, I get the following :

COPYING data scripts  
EXCEPTIONS-CLIENT docs share  
INSTALL-BINARY include sql-bench  
README lib support-files  
bin man tests  
configure mysql-test yo.txt

If I type in : “cd /usr/local/mysql/bin” followed by “ls” the Terminal  
window then displays the following :

CMakeLists.txt mysqld-debug  
comp\_err mysqld\_multi  
comp\_sql.c mysqld\_safe  
make\_sharedlib\_distribution mysqldump  
make\_win\_bin\_dist mysqldumpslow  
make\_win\_src\_distribution mysqlhotcopy  
msql2mysql mysqlimport  
my\_print\_defaults mysqlmanager  
myisam\_ftdump mysqlshow  
myisamchk mysqltest  
myisamlog mysqltestmanager  
myisampack mysqltestmanager-pwgen  
mysql mysqltestmanagerc  
mysql\_client\_test ndb\_config  
mysql\_config ndb\_cpcd  
mysql\_convert\_table\_format ndb\_delete\_all  
mysql\_explain\_log ndb\_desc  
mysql\_find\_rows ndb\_drop\_index  
mysql\_fix\_extensions ndb\_drop\_table  
mysql\_fix\_privilege\_tables ndb\_error\_reporter  
mysql\_fix\_privilege\_tables\_sql.c ndb\_mgm  
mysql\_secure\_installation ndb\_mgmd  
mysql\_setpermission ndb\_restore  
mysql\_tableinfo ndb\_select\_all  
mysql\_tzinfo\_to\_sql ndb\_select\_count  
mysql\_upgrade ndb\_show\_tables  
mysql\_upgrade\_shell ndb\_size.pl  
mysql\_waitpid ndb\_test\_platform  
mysql\_zap ndb\_waiter  
mysqlaccess ndbd  
mysqlaccess.conf perror  
mysqladmin replace  
mysqlbinlog resolve\_stack\_dump  
mysqlbug resolveip  
mysqlcheck safe\_mysqld  
mysqld

The directory listing displayed immediately above looks to me like all  
the binaries needed for a successful MySQL installation under Mac OSX  
are where they’re supposed to be (bearing in mind, of course, that I’m  
really pretty much a MySQL ignoramus and I really don’t know what I’m  
talking about).

If I open up a Terminal window and type in the following string : “ps -  
ax | grep mysql”.

The Terminal window then displays the following text :

215 ?? S 0:00.03 /bin/sh ./bin/mysqld\_safe --datadir=/usr/local/  
mysql/dat  
234 ?? S 0:01.19 /usr/local/mysql/bin/mysqld --basedir=/usr/  
local/mysql -  
268 p1 U+ 0:00.00 grep mysql

I’m assuming here that this mans the MySQL is running properly. But,  
to tell you the truth, I’m too ignorant and inexperienced to really  
know whether this is true or not.

On page 30 of BYORORWA Patrick tells me to type into the Terminal  
Window : “mysqld”.

When I do that I get the following text displaying in the Terminal  
window :

simon-whelans-power-mac-g5:/usr/local/mysql/bin simonwhelan$ mysqld  
070802 20:26:26 [Warning] Can’t create test file /usr/local/  
mysql-5.0.45-osx10.4-powerpc/data/simon-whelans-power-mac-g5.lower-  
test  
070802 20:26:26 [Warning] Can’t create test file /usr/local/  
mysql-5.0.45-osx10.4-powerpc/data/simon-whelans-power-mac-g5.lower-  
test  
mysqld: Can’t change dir to ‘/usr/local/mysql-5.0.45-osx10.4-powerpc/  
data/’ (Errcode: 13)  
070802 20:26:26 [ERROR] Aborting

070802 20:26:26 [Note] mysqld: Shutdown complete

The bottom of page 30 of BYORORW sez I should get text that looks  
something like the following :

Welcome to the MySQL monitor. Commands end with : or \g.  
Your MySQL connection id is 8 to server version 5.0.45

Type ‘help’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

Clearly something is wrong. The problem is that I don’t know what went  
wrong nor do I know how to fix it.

It occurred to me that I might not be entering the right command so I  
tried a few others; i.e. :

When I typed in “mysql”, I got :

ERROR 1045 (28000): Access denied for user  
‘simonwhelan’@‘localhost’ (using password: NO)

When I typed in “mysql\_safe”, I got :

touch: /usr/local/mysql/data/simon-whelans-power-mac-g5.local.err:  
Permission denied  
chown: /usr/local/mysql/data/simon-whelans-power-mac-g5.local.err:  
Permission denied  
Starting mysqld daemon with databases from /usr/local/mysql/data  
/usr/local/mysql/bin/mysqld\_safe: line 380: /usr/local/mysql/data/  
simon-whelans-power-mac-g5.local.err: Permission denied  
rm: /tmp/mysql.sock: Permission denied  
rm: /usr/local/mysql/data/simon-whelans-power-mac-g5.local.pid:  
Permission denied  
/usr/local/mysql/bin/mysqld\_safe: line 386: /usr/local/mysql/data/  
simon-whelans-power-mac-g5.local.err: Permission denied  
STOPPING server from pid file /usr/local/mysql/data/simon-whelans-  
power-mac-g5.local.pid  
tee: /usr/local/mysql/data/simon-whelans-power-mac-g5.local.err:  
Permission denied  
070802 20:27:07 mysqld ended  
tee: /usr/local/mysql/data/simon-whelans-power-mac-g5.local.err:  
Permission denied

When I typed in “mysqltest”, I got :

mysqltest: Could not open connection ‘default’: 1045 Access denied for  
user ‘simonwhelan’@‘localhost’ (using password: NO)  
not ok

Clearly something is wrong. The problem is, as I’ve said more than  
once above I really don’t know enough about what I’m doing to  
understand what the problem is much less fix it.

So folks, my questions are :

1. What’s wrong; i.e. : why am I not getting text displaying on the  
Terminal window more or less like the text that Patrick sez I should  
be getting on the bottom of page 30 of BYORORW ?
2. What do I need to do to fix the problem; i.e. : get text displaying  
in my Terminal window that at least displays the text that Patrick  
claims I should be getting ?

Any advice, suggestions and help that you could send my way would be  
greatly appreciated !

Just think, if I can solve this problem then I can move on to actual  
Ruby and Rails problems rather than set up and installation problems !  
Oh, Joy !

All the best & I hope to hear from you soon … Simon.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 3, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195/2 "2007-08-03T19:31:39Z")

</div>

Hey Simon, fret not!

First, there’s the instructions from MySQL:

[http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html](http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html)

Second, if you can’t get that running properly there is an article at  
Apple on building from source (although that makes keeping the system  
current a little more difficult for non-unix types):

[http://developer.apple.com/internet/opensource/osdb.html](http://developer.apple.com/internet/opensource/osdb.html)

Even harder than that, will be the magic, top-secret voodoo required  
to get ruby-mysql installed on OS X, to which I have yet to accomplish.

Being a PostgreSQL homer means I just did everything in PostgreSQL,  
but I will eventually need to have access to MySQL from Ruby. Anyone  
else out there know the trick to get ruby-mysql to build with the  
stock MySQL dmg provided by [MySQL.com](http://MySQL.com)?

– Mitch

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 3, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195/3 "2007-08-03T19:35:12Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Email : removed\_email\_address@domain.invalid
> 
> As Dr. Nick of the Simpsons sez :

I will stat by applauding your thoroughness in prodivifn as much  
information as possible. The being said… I felt flooded. 😉

Some thing you needs to understand.

1. Your mysql seems to be installed properly. Executing ‘mysql’ will try  
and fired up the client, since you have provided no parameters it will  
assume defaults. So what’s doing behind the scenes is that it’s  
connecting as you “Simon” but your user may have no permissions. Try  
connecting as ‘su’ and then "GRANT"ing permission to your username.

ex: mysql -uroot -p mysql

Then read here for info on CREATING a database and GRANT(ing)  
permissions to a user FOR That database.

[http://dev.mysql.com/doc/refman/5.0/en/create-database.html](http://dev.mysql.com/doc/refman/5.0/en/create-database.html)  
[http://dev.mysql.com/doc/refman/5.0/en/grant.html](http://dev.mysql.com/doc/refman/5.0/en/grant.html)

Moving along…

Once this is done you now need to CONFIGURE rails to use that database.  
You do that by editing the database.yml file in “your project”/config  
folder.

put in the appropriate username / password and database (you’ve  
hopefully just setup in mysql above) and you’re home free.

Once you get this done, let us know if you have any more problems.

Thanks and I hope this helps.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 3, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195/4 "2007-08-03T19:54:42Z")

</div>

Quoting Mitch P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), who spaketh thusly:

> Anyone  
> else out there know the trick to get ruby-mysql to build with the  
> stock MySQL dmg provided by [MySQL.com](http://MySQL.com)?

I just tried the following line:

sudo gem install mysql –  
–with-mysql-config=/usr/local/mysql/bin/mysql\_config

…from the Hivelogic narrative:

> **[Dan Benjamin](https://danbenjamin.com)**
>
> Dan Benjamin's personal website.

…and it worked. I must have had something stale lying around when I  
tried earlier, hrm.

– Mitch

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 4, 2007, 8:45pm UTC](https://www.ruby-forum.com/t/arather-basic-and-rather-stupid-mysql-question/111195/5 "2007-08-04T20:45:49Z")

</div>

Email : removed\_email\_address@domain.invalid

If I can do it then it can’t be done ! … - Anonymous

Hi Mitch & Jean :

1st off, I’d like to thank you for your help and suggestions.

THANK YOU !!!

I’m glad to hear that I at least seem to have installed MySQL  
properly. At least I’m able to do at least something right.

Unfortunately, I’m just too ignorant of the basics of both Unix  
command lines and MySQL commands to understand them.

But, before I get into plumbing the depths of my Unix/MySQL ignorance  
I figure I should give you the source for the rails file that contains  
the configuration data for using the database.

If I’ve got this right, it’s located in a file called : “/Development/  
Users/cyf/config/database.yml” (by the way, just in case you’re  
wondering, ‘cyf’ is the name of my Ruby on Rails project). That file  
contains the following text :

\<START “/Development/Users/cyf/config/database.yml”\>

# MySQL (default setup). Versions 4.1 and 5.0 are recommended.

# 

# Install the MySQL driver:

# gem install mysql

# On MacOS X:

# gem install mysql – --include=/usr/local/lib

# On Windows:

# gem install mysql

# Choose the win32 build.

# Install MySQL and put its /bin directory on your path.

# 

# And be sure to use new-style password hashing:

# [http://dev.mysql.com/doc/refman/5.0/en/old-client.html](http://dev.mysql.com/doc/refman/5.0/en/old-client.html)

development:  
adapter: mysql  
database: cyf\_development  
username: root  
password:  
socket: /tmp/mysql.sock

# 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: mysql  
database: cyf\_test  
username: root  
password:  
socket: /tmp/mysql.sock

production:  
adapter: mysql  
database: cyf\_production  
username: root  
password:  
socket: /tmp/mysql.sock

\<END “/Development/Users/cyf/config/database.yml”\>

The problem is that I have no idea what :

Try \_connecting as ‘su’ and then "GRANT"ing permission to your  
username.  
ex: mysql -uroot -p mysql

means.

If have no idea what “connecting as su” means.

I also have no idea how to go about "“GRANT"ing permission to your  
username.”.

If I fire up a Terminal window and I type in :

su mysql -uroot -p mysql

followed by pressing the “Return” key I get :

Password:

If I type in my password (which I think is “simon”) followed by  
pressing the 'Return" key, I get the following :

su: Sorry  
simon-whelans-power-mac-g5:~ simonwhelan$

The truth is I’m not even sure what my “username” (I think it’s  
“simonwhelan”) and what my “password” (I think it’s “simon”) are.

So, at this point, given my abysmal ignorance of both Unix and MySQL,  
the questions I need to ask are as follows :

1. What is my “username” ?
2. How do I find my “username” ?
3. What is my “password” ?
4. How do I find my “password” ?
5. How EXACTLY do I go about “GRANT"ing permission to my username” ?

I realize that to someone who is both familiar with Unix and  
comfortable with MySQL that my questions may seem both rudimentary and  
ridiculous to the point of being insulting but the simple, sad and  
sordid truth is that I am actually that ignorant of the both  
intricacies of Unix and the workings of MySQL.

I’m also confused by the following sentence :

Then read here for info on CREATING a database and GRANT(ing)  
\_permissions to a user FOR That database.

Patrick Lenz makes no mention of these steps on page 30 of BYORORWA.  
Did he forget to mention that you have to both create a database and  
then grant permissions to use it or I am I missing something here ?  
I’m inferring (perhaps incorrectly) that the database has already been  
both created and its permissions granted from my reading of Lenz’s  
rather skimpy text regarding this on pages 29-31 under the section  
entitled : “Installing MySQL on a Mac”. Did he leave stuff out or am  
I missing something because I just don’t know enough about both Unix  
and MySQL ?

I have to tell you that I have the distinct (and quite possibly  
erroneous) impression that Lenz didn’t even both testing his Mac OSX  
instructions to verify that they actually work.

Anyhow, any advice, suggestions and help that you could send my way  
would be greatly appreciated !

And, by the way, thank you for all the help you’ve so kindly sent me  
so far !

All the best & I hope to hear from you soon … Simon.
