Arather basic and rather stupid MySQL question

Email : [email protected]

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

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/” 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.

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

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

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?

– Mitch

[email protected] wrote:

Email : [email protected]

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. :wink:

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/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.

Quoting Mitch P. [email protected], 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?

I just tried the following line:

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

…from the Hivelogic narrative:

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

– Mitch

Email : [email protected]

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

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.