Forum: Ruby on Rails mySQL setup - I'm losing it here.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ryan O. (Guest)
on 2008-12-19 21:19

Newbie here (who else.) I  feel confident I can excel in the actual
programming of rails apps. But all the tutorials just glaze over mySQL
which seems to me, by far, the most problematic area for new users.

I have tried a ton of different things here. I know mySQL is installed
and running in one place or another. I don't know how to tell my rails
app with the hell to do about it. I do have the "Welcome Aboard" screen
showing at localhost:3000 with the following details:

    Ruby version    1.8.6 (i686-darwin8.9.1)
    RubyGems version    0.9.2
    Rails version    1.2.3
    Active Record version    1.15.3
    Action Pack version    1.13.3
    Action Web Service version    1.2.3
    Action Mailer version    1.3.3
    Active Support version    1.4.2
    Application root    /Users/rmorourk/Sites/depot
    Environment    development
    Database adapter    mysql

When I try to do something with the database here is what I run into.

    bio4054059:depot rmorourk$ rake  db:migrate
    (in /Users/rmorourk/Sites/depot)
    rake aborted!
    Unknown database 'depot_development'

The development portion of my database.yml file looks like this:

    development:
      adapter: mysql
      database: depot_development
      username: root
      password: root
      host: localhost
      socket: /Applications/MAMP/tmp/mysql/mysql.sock

I added the socket line after I installed MAMP as per a tutorial... But
when I am in the terminal and I want to do something with the database,
like;

    bio4054059:depot rmorourk$ mysql -uroot depot_development
    -bash: mysql: command not found

I get the error on the second line --- any advise? I assume this has to
be a issue of im not telling something to look in the right somewhere,
but I am about ready to put my fist in the wall on this thing. I would
LOVE some advise!

Thanks!!
Sadeesh V. (Guest)
on 2008-12-19 21:33
(Received via mailing list)
Hello Ryan,

              Make sure you have only one mysql in ur machine and
there is database with name 'depot_development' and try again.

Thanks,
Sadeesh.

On Dec 20, 12:19 am, Ryan O. <removed_email_address@domain.invalid>
Rick (Guest)
on 2008-12-19 21:46
(Received via mailing list)
Hello Ryan,

>     bio4054059:depot rmorourk$ mysql -uroot depot_development
>     -bash: mysql: command not found

"command not found" is your shell telling you that whatever directory
you have installed  mysql in to is not on your search path.

If you type "print $PATH" you will see a colon separated ordered list
of directories that are searched for executable commands.  To
temporarily extend the list just type: set PATH=MYSQLHOME:$PATH where
MYSQLHOME is the full path to the directory containing mysql
executable. i.e. MSQLHOME might be /usr/local/mysql/bin.  You should
then be able to execute  the mysql -uroot... command.

Once you have success with this, you should modify your shell startup
file to make the PATH change permanent.  Depending on what shell you
use this could be .profile, .cshrc, .tshrc, ...

Rick
Hassan S. (Guest)
on 2008-12-19 21:49
(Received via mailing list)
On Fri, Dec 19, 2008 at 11:19 AM, Ryan O.
<removed_email_address@domain.invalid> wrote:

> I have tried a ton of different things here. I know mySQL is installed
> and running in one place or another. I don't know how to tell my rails
> app with the hell to do about it. I
> When I try to do something with the database here is what I run into.
>
>    bio4054059:depot rmorourk$ rake  db:migrate
>    (in /Users/rmorourk/Sites/depot)
>    rake aborted!
>    Unknown database 'depot_development'

So you haven't created that database yet. No mystery there. :-)

> when I am in the terminal and I want to do something with the database,
> like;
>
>    bio4054059:depot rmorourk$ mysql -uroot depot_development
>    -bash: mysql: command not found

Which simply means MySQL isn't in your PATH. You need to find
where the MySQL executables are installed and add that directory
to your path. Or create symlinks to, say, /usr/local/bin.

This is just basic *nix stuff.

HTH,
--
Hassan S. ------------------------ removed_email_address@domain.invalid
Ryan O. (Guest)
on 2008-12-19 21:52
Rick wrote:
> Hello Ryan,
>
>> � � bio4054059:depot rmorourk$ mysql -uroot depot_development
>> � � -bash: mysql: command not found
>
> "command not found" is your shell telling you that whatever directory
> you have installed  mysql in to is not on your search path.
>
> If you type "print $PATH" you will see a colon separated ordered list
> of directories that are searched for executable commands.  To
> temporarily extend the list just type: set PATH=MYSQLHOME:$PATH where
> MYSQLHOME is the full path to the directory containing mysql
> executable. i.e. MSQLHOME might be /usr/local/mysql/bin.  You should
> then be able to execute  the mysql -uroot... command.
>
> Once you have success with this, you should modify your shell startup
> file to make the PATH change permanent.  Depending on what shell you
> use this could be .profile, .cshrc, .tshrc, ...
>
> Rick

Thanks, here is what I tried:

bio4054059:~ rmorourk$ print $PATH
-bash: print: command not found
bio4054059:~ rmorourk$ set PATH=/Applications/MAMP/tmp/mysql/:$PATH
bio4054059:~ rmorourk$ mysql -uroot
-bash: mysql: command not found

Any ideas? I'm using the default terminal on MAC OS X..
Ryan O. (Guest)
on 2008-12-19 22:02
> Which simply means MySQL isn't in your PATH. You need to find
> where the MySQL executables are installed and add that directory
> to your path. Or create symlinks to, say, /usr/local/bin.

First, how do I add it to my PATH? Second, I used this to install mySQL:
http://www.mamp.info/en/index.php

Not sure if that was necessary/proper.

The install folder for MAMP has this:
/Applications/MAMP/tmp/mysql/

Which holds two files mysql.pid and mysqp.sock - am I correct in
assuming that those are the executables I need to set my path too?

Symlinks?

Thanks for the help thus far!
Freddy A. (Guest)
on 2008-12-19 22:03
(Received via mailing list)
How did you install mysql?

If you used port then its mysql5 not mysql which is the command to
open the mysql client...

If you are trying to install mysql using anything other than
macports.. dont't... I recommend that you go to macports.org site and
download the latest version...



On Dec 19, 12:02 pm, Ryan O. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2008-12-19 22:32
(Received via mailing list)
On Fri, Dec 19, 2008 at 12:02 PM, Ryan O.
<removed_email_address@domain.invalid> wrote:

> First, how do I add it to my PATH? Second, I used this to install mySQL:
> http://www.mamp.info/en/index.php
>
> Not sure if that was necessary/proper.

Definitely not necessary, but whatever -- let's assume it worked
for the moment :-)

> The install folder for MAMP has this:
> /Applications/MAMP/tmp/mysql/
>
> Which holds two files mysql.pid and mysqp.sock - am I correct in
> assuming that those are the executables I need to set my path too?

No. The first contains the process id of the mysql server, and the
other is the socket used to communicate with it.

I'd imagine that somewhere under /Applications/MAMP is a directory
with a bunch of files with names starting with mysql. Look around, or
run this from a prompt:

find /Application/MAMP -type f -name 'mysql*' -print

> Symlinks?

Um, I'd recommend doing a little reading up on general *nix/shell
use.  ("symlinks" is short for "symbolic links" -- a way to have a file
referenced from a different directory than it's really located in.)
But we can skip that for now; you just need to find what to add to
your PATH. And Rick already explained that.

Oh, yeah, but it's `echo $PATH`, not `print`.

HTH,
--
Hassan S. ------------------------ removed_email_address@domain.invalid
Tim McIntyre (Guest)
on 2008-12-19 23:20
(Received via mailing list)
Try

/Applications/MAMP/Library/bin/mysql -u root

http://my.safaribooksonline.com/9780321606709/app0...

good luck!
Tim

On Dec 19, 11:19 am, Ryan O. <removed_email_address@domain.invalid>
Tim McIntyre (Guest)
on 2008-12-19 23:22
(Received via mailing list)
Tim McIntyre (Guest)
on 2008-12-19 23:25
(Received via mailing list)
Ryan O. (Guest)
on 2008-12-20 01:46
> I'd imagine that somewhere under /Applications/MAMP is a directory
> with a bunch of files with names starting with mysql. Look around, or
> run this from a prompt:

So I found the folder (who's contents I am going to list in my output in
a second) with all the files starting with mysql. It is located here:
Applications/MAMP/Library/bin - Here is what an ls of the dir revealed:

bio4054059:bin rmorourk$ ls
ab        mysql_convert_table_format
apachectl      mysql_explain_log
apr-config      mysql_find_rows
apu-config      mysql_fix_extensions
apxs        mysql_fix_privilege_tables
autopoint      mysql_install_db
checkgid      mysql_secure_installation
cjpeg        mysql_setpermission
comp_err      mysql_tableinfo
curl        mysql_tzinfo_to_sql
curl-config      mysql_upgrade
dbmmanage      mysql_upgrade_shell
djpeg        mysql_waitpid
envsubst      mysql_zap
envvars        mysqlaccess
envvars-std      mysqladmin
freetype-config      mysqlbinlog
gettext        mysqlbug
gettext.sh      mysqlcheck
gettextize      mysqld_multi
htdbm        mysqld_safe
htdigest      mysqldump
htpasswd      mysqldumpslow
httpd        mysqlhotcopy
httxt2dbm      mysqlimport
iconv        mysqlshow
idn        mysqltest
innochecksum      mysqltestmanager
jpegtran      mysqltestmanager-pwgen
libmcrypt-config    mysqltestmanagerc
libpng-config      ngettext
libpng12-config      perror
libtool        rdjpgcom
libtoolize      recode-sr-latin
logresolve      replace
msgattrib      resolve_stack_dump
msgcat        resolveip
msgcmp        rotatelogs
msgcomm        sabcmd
msgconv        sablot-config
msgen        type1afm
msgexec        wrjpgcom
msgfilter      xgettext
msgfmt        xml2-config
msggrep        xmlcatalog
msginit        xmllint
msgmerge      xslt-config
msgunfmt      xsltproc
msguniq        yaz-asncomp
msql2mysql      yaz-client
my_print_defaults    yaz-config
myisam_ftdump      yaz-iconv
myisamchk      yaz-icu
myisamlog      yaz-illclient
myisampack      yaz-marcdump
mysql        yaz-ztest
mysql_client_test    zoomsh
mysql_config

Assuming this was what I had been searching for, I did this:

bio4054059:bin rmorourk$ echo $PATH
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/bin:/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/sbin:/Users/rmorourk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
bio4054059:bin rmorourk$ set PATH=Applications/MAMP/Library/bin:$PATH
bio4054059:bin rmorourk$ cd .. .. .. .. .. ..
bio4054059:Library rmorourk$ cd ..
bio4054059:MAMP rmorourk$ cd ..
bio4054059:Applications rmorourk$ cd ..
bio4054059:/ rmorourk$ cd Users/rmorourk/Sites/depot/
bio4054059:depot rmorourk$ mysqladmin -u root create depot_devdb
-bash: mysqladmin: command not found
bio4054059:depot rmorourk$ mysql -U
-bash: mysql: command not found
bio4054059:depot rmorourk$

As you can see the mysql command still isn't found, any thoughts? I feel
like we are getting closer. Thanks for the help thus far!!
Tim McIntyre (Guest)
on 2008-12-20 01:54
(Received via mailing list)
I think

set PATH=Applications/MAMP/Library/bin:$PATH

should be

set PATH=/Applications/MAMP/Library/bin:$PATH

looks like it's there and even without setting the path you should be
able to do:

/Applications/MAMP/Library/bin/mysql -u root

hope that helps
Tim

On Dec 19, 3:46 pm, Ryan O. <removed_email_address@domain.invalid>
Ryan O. (Guest)
on 2008-12-20 03:44
> set PATH=Applications/MAMP/Library/bin:$PATH
>
> should be
>
> set PATH=/Applications/MAMP/Library/bin:$PATH
>
> looks like it's there and even without setting the path you should be
> able to do:
>
> /Applications/MAMP/Library/bin/mysql -u root


So based on this here is what I've done. It seems to be creating the
database but then the rake command is saying there is no such database?

bio4054059:depot rmorourk$ /Applications/MAMP/Library/bin/mysql
mysqladmin -u root -p root create depot_development

/Applications/MAMP/Library/bin/mysql  Ver 14.12 Distrib 5.0.41, for
apple-darwin8.11.1 (i686) using  EditLine wrapper
Copyright (C) 2002 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: /Applications/MAMP/Library/bin/mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to
use
                      'rehash' to get table and field completion, but
startup
                      and reconnecting may take a longer time. Disable
with
                      --disable-auto-rehash.
  -A, --no-auto-rehash
                      No automatic rehashing. One has to use 'rehash' to
get
                      table and field completion. This gives a quicker
start of
                      mysql and disables rehashing on reconnect.
WARNING:
                      options deprecated; use --disable-auto-rehash
instead.
  -B, --batch         Don't use history file. Disable interactive
behavior.
                      (Enables --silent)
  --character-sets-dir=name
                      Directory where character sets are.
  --default-character-set=name
                      Set the default character set.
  -C, --compress      Use compression in server/client protocol.
  -#, --debug[=#]     This is a non-debug version. Catch this and exit
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  -e, --execute=name  Execute command and quit. (Disables --force and
history
                      file)
  -E, --vertical      Print the output of a query (rows) vertically.
  -f, --force         Continue even if we get an sql error.
  -G, --named-commands
                      Enable named commands. Named commands mean this
program's
                      internal commands; see mysql> help . When enabled,
the
                      named commands can be used from any line of the
query,
                      otherwise only from the first line, before an
enter.
                      Disable with --disable-named-commands. This option
is
                      disabled by default.
  -g, --no-named-commands
                      Named commands are disabled. Use \* form only, or
use
                      named commands only in the beginning of a line
ending
                      with a semicolon (;) Since version 10.9 the client
now
                      starts with this option ENABLED by default!
Disable with
                      '-G'. Long format commands still work from the
first
                      line. WARNING: option deprecated; use
                      --disable-named-commands instead.
  -i, --ignore-spaces Ignore space after function names.
  --local-infile      Enable/disable LOAD DATA LOCAL INFILE.
  -b, --no-beep       Turn off beep on error.
  -h, --host=name     Connect to host.
  -H, --html          Produce HTML output.
  -X, --xml           Produce XML output
  --line-numbers      Write line numbers for errors.
  -L, --skip-line-numbers
                      Don't write line number for errors. WARNING: -L is
                      deprecated, use long version of this option
instead.
  -n, --unbuffered    Flush buffer after each query.
  --column-names      Write column names in results.
  -N, --skip-column-names
                      Don't write column names in results. WARNING: -N
is
                      deprecated, use long version of this options
instead.
  -O, --set-variable=name
                      Change the value of a variable. Please note that
this
                      option is deprecated; you can set variables
directly with
                      --variable-name=value.
  --sigint-ignore     Ignore SIGINT (CTRL-C)
  -o, --one-database  Only update the default database. This is useful
for
                      skipping updates to other database in the update
log.
  --pager[=name]      Pager to use to display results. If you don't
supply an
                      option the default pager is taken from your ENV
variable
                      PAGER. Valid pagers are less, more, cat [>
filename],
                      etc. See interactive help (\h) also. This option
does not
                      work in batch mode. Disable with --disable-pager.
This
                      option is disabled by default.
  --no-pager          Disable pager and print to stdout. See interactive
help
                      (\h) also. WARNING: option deprecated; use
                      --disable-pager instead.
  -p, --password[=name]
                      Password to use when connecting to server. If
password is
                      not given it's asked from the tty.
  -P, --port=#        Port number to use for connection.
  --prompt=name       Set the mysql prompt to this value.
  --protocol=name     The protocol of connection
(tcp,socket,pipe,memory).
  -q, --quick         Don't cache result, print it row by row. This may
slow
                      down the server if the output is suspended.
Doesn't use
                      history file.
  -r, --raw           Write fields without conversion. Used with
--batch.
  --reconnect         Reconnect if the connection is lost. Disable with
                      --disable-reconnect. This option is enabled by
default.
  -s, --silent        Be more silent. Print results with a tab as
separator,
                      each row on new line.
  -S, --socket=name   Socket file to use for connection.
  -t, --table         Output in table format.
  -T, --debug-info    Print some debug info at exit.
  --tee=name          Append everything into outfile. See interactive
help (\h)
                      also. Does not work in batch mode. Disable with
                      --disable-tee. This option is disabled by default.
  --no-tee            Disable outfile. See interactive help (\h) also.
WARNING:
                      option deprecated; use --disable-tee instead
  -u, --user=name     User for login if not current user.
  -U, --safe-updates  Only allow UPDATE and DELETE that uses keys.
  -U, --i-am-a-dummy  Synonym for option --safe-updates, -U.
  -v, --verbose       Write more. (-v -v -v gives the table output
format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
  --connect_timeout=# Number of seconds before connection timeout.
  --max_allowed_packet=#
                      Max packet length to send to, or receive from
server
  --net_buffer_length=#
                      Buffer for TCP/IP and socket communication
  --select_limit=#    Automatic limit for SELECT when using
--safe-updates
  --max_join_size=#   Automatic limit for rows in a join when using
                      --safe-updates
  --secure-auth       Refuse client connecting to server if it uses old
                      (pre-4.1.1) protocol
  --show-warnings     Show warnings after every statement.

Default options are read from the following files in the given order:
/etc/my.cnf ~/.my.cnf /Applications/MAMP/conf/my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults  Print the program argument list and exit
--no-defaults    Don't read default options from any options file
--defaults-file=#  Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- -----------------------------
auto-rehash                       TRUE
character-sets-dir                (No default value)
default-character-set             latin1
compress                          FALSE
database                          (No default value)
delimiter                         ;
vertical                          FALSE
force                             FALSE
named-commands                    FALSE
local-infile                      FALSE
no-beep                           FALSE
host                              (No default value)
html                              FALSE
xml                               FALSE
line-numbers                      TRUE
unbuffered                        FALSE
column-names                      TRUE
sigint-ignore                     FALSE
port                              0
prompt                            mysql>
quick                             FALSE
raw                               FALSE
reconnect                         TRUE
socket                            (No default value)
table                             FALSE
debug-info                        FALSE
user                              root
safe-updates                      FALSE
i-am-a-dummy                      FALSE
connect_timeout                   0
max_allowed_packet                16777216
net_buffer_length                 16384
select_limit                      1000
max_join_size                     1000000
secure-auth                       FALSE
show-warnings                     FALSE

bio4054059:depot rmorourk$ rake db:migrate(in
/Users/rmorourk/Sites/depot)
rake aborted!
Unknown database 'depot_development'

(See full trace by running task with --trace)
bio4054059:depot rmorourk$

Thoughts?
Norm (Guest)
on 2008-12-20 05:03
(Received via mailing list)
Ryan O. wrote:
>> and you are welcome to modify and redistribute it under the GPL license
>> Usage: /Applications/MAMP/Library/bin/mysql [OPTIONS] [database]
>>
Whenever you see a message starting "Usage:" it means you did not give
the correct options and the program will then go on and tell you what
the options really are (in this case in a lot of detail).  You in this
case entered the wrong command:  You apparently entered:
/Applications/MAMP/Library/bin/mysql mysqladmin -u root -p root create
depot_development
and correctly got an error message from mysql telling you that the
options were all screwed up.
What you really want is:
/Applications/MAMP/Library/bin/mysqladmin -u root -p root create
depot_development
This will probably work and give you no output message (most Unix/Linux
commands are silent on success).  Mysqladmin is a standalone command not
a subcommand of mysql.  You probably should not have to enter the full
pathname but it will work.

Norm
Ryan O. (Guest)
on 2008-12-20 05:12
> What you really want is:
> /Applications/MAMP/Library/bin/mysqladmin -u root -p root create
> depot_development

Interesting, thanks... but now I am getting a problem with the password.
Observe:

bio4054059:depot rmorourk$ /Applications/MAMP/Library/bin/mysqladmin -u
root -p root create depot_development
Enter password:
/Applications/MAMP/Library/bin/mysqladmin: Unknown command: 'root'
bio4054059:depot rmorourk$

When prompted for the password I typed root - which is what the password
is (at least in the database.yml file) but it gives me an unknown
command output?
Norm (Guest)
on 2008-12-20 05:24
(Received via mailing list)
Ryan O. wrote:
> Enter password:
> /Applications/MAMP/Library/bin/mysqladmin: Unknown command: 'root'
> bio4054059:depot rmorourk$
>
> When prompted for the password I typed root - which is what the password
> is (at least in the database.yml file) but it gives me an unknown
> command output?
>
>
>
>
Rather inconsistently there should be a space between the -u and the
username but there must not be a space between the -p and the password.
an alternative is to use:
mysqladmin --user=root --password=root create depot_development
notice the double minus on the options in this form.  man mysqladmin
will give you information on the options and usage of the command.

Norm
Rick (Guest)
on 2008-12-20 08:26
(Received via mailing list)
OK so now we know you're using bash, substitute "echo" for "print" in
my previous mail.
Rick

On Dec 19, 9:52 am, Ryan O. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.