msjit / testcasedb

TestCaseDB - Web based test case management
MIT License
40 stars 18 forks source link

How to Solve - Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error) #15

Closed harshith30 closed 10 years ago

harshith30 commented 10 years ago

Hi, I have followed every instructions given the pdf , but when i try to run rails server , it starts and exits. below is the procedure which i followed , i have also included the details about the database.yml which resides in /tcb/tcb/config folder


[harshith@localhost ~]$ mysql -u root -p Enter password: p@ssw0rd

Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.37-MariaDB MariaDB Server

MariaDB [(none)]> create database tcdb_development; Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create database tcdb_production; Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'harshith'@'localhost' IDENTIFIED BY 'dbadmin'; Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON tcdb_production.* TO 'harshith'@'localhost' IDENTIFIED BY 'dbadmin';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for harshith@localhost; +-----------------------------------------------------------------------------------------------------------------+ | Grants for harshith@localhost | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON . TO 'harshith'@'localhost' IDENTIFIED BY PASSWORD '_354A2C82FFA72984AE659BF47BBA109EF0D89CA5' | | GRANT ALL PRIVILEGES ON tcdb_production._ TO 'harshith'@'localhost' | +-----------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)


Config File Details from ~/tcdb/tcdb/config

SQLite version 3.x

gem install sqlite3

production: adapter: mysql2 database: tcdb_development encoding: utf8 username: harshith password: dbadmin pool: 5 timeout: 5000


[root@localhost testcasedb]# rails server

WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1 => Booting WEBrick => Rails 3.2.14 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting

/usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in connect': Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error) from /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:ininitialize'


[harshith@localhost testcasedb]$ which rake /usr/local/bin/rake

so what instructions should i follow to fix this problem.

Thanks Harshith

joffems commented 10 years ago

The issue is that you've put your DB setup in the production section, but you're starting the server in development mode. Depending on your goals, you have 2 options:

  1. Start the server in production mode, 'bundle exec rails server -e production'
  2. Move the config in ~/tcdb/tcdb/config to the development section and then try starting the server.
harshith30 commented 10 years ago

Hi, What caused those errors were i did not update ~/testcased/config/database.yml file , i made the same changes to this file as i did for ~/tcdb/tcdb/database.yml file which was mentioned in the pdf file.

   #SQLite version 3.x
   #gem install sqlite3
   production:
   adapter: mysql2
   database: tcdb_development
   encoding: utf8
   username: harshith
   password: dbadmin
   pool: 5
   timeout: 5000

And when i try to run the server in the production mode , the server starts without trouble

   [root@localhost testcasedb]# bundle exec rails server -e production
    WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1
    => Booting WEBrick
    => Rails 3.2.14 application starting in production on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.14/lib/active_support /dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.

     [2014-06-26 11:36:48] INFO  WEBrick 1.3.1
     [2014-06-26 11:36:48] INFO  ruby 1.9.3 (2014-05-14) [x86_64-linux]
     [2014-06-26 11:36:48] INFO  WEBrick::HTTPServer#start: pid=3302 port=3000

  But when i access localhost:3000 on my browser i get an error page and the tab name displays   TestCaseDB(500) .

  The contents in the terminal after i start the localhost:3000 looks as follows

 Started GET "/" for 127.0.0.1 at 2014-06-26 11:40:04 +0530
 Processing by HomeController#index as HTML
 Redirected to http://localhost:3000/login?referer=%2F
 Filter chain halted as :require_login rendered or redirected
 Completed 302 Found in 2ms (ActiveRecord: 0.0ms)
 Started GET "/login?referer=%2F" for 127.0.0.1 at 2014-06-26 11:40:04 +0530

 NoMethodError (undefined method `value' for nil:NilClass):
 app/controllers/application_controller.rb:107:in `google_auth_enabled'

 Processing by UserSessionsController#new as HTML
 Parameters: {"referer"=>"/"}
 Completed 500 Internal Server Error in 3ms

screenshot from 2014-06-26 11 47 40


I would like to know how to solve this , am i in the right track or have i done some mistakes.

Thanks Harshith

kirantpatil commented 10 years ago

I think you need to provide the Google auth client id and secret to the below file and do db migration.

db/migrate/20140605100724_create_settings_google_auth.rb

joffems commented 10 years ago

The issue is that the migration accidentally sets Google Auth to enabled instead of disabled by default.

If you run the query below, google auth will be disabled and you should be able to load the login page.

update settings set value='Disabled' where name='Google Auth enabled'

I will push a fix to change the default setting.

kirantpatil commented 10 years ago

Google auth enable or disable option should be mentioned in application configuration file, for example https://github.com/gitlabhq/gitlabhq/blob/master/config/gitlab.yml.example.

That way options can be placed in one place for future feature expansion.

harshith30 commented 10 years ago

Hi , I'm not sure why but for some reason when i run the command
update settings set value='Disabled' where name='Google Auth enabled' gives Query OK, 0 rows affected (0.35 sec) Rows matched: 0 Changed: 0 Warnings: 0

So just to make sure i did not make any mistakes , i cloned  a fresh copy of the project 
 and tcdb folder. i also created  a new tcdb_production database .

The steps which i followed are as follows
-----------------------------------------------------------------------------------------------------------------------------

 #Creating Database with credentials 

 [harshith@localhost ~]$ mysql -u root -p
 Enter password: 

 MariaDB [(none)]> CREATE USER `harshith`@`localhost` IDENTIFIED BY 'dbadmin';
 Query OK, 0 rows affected (0.00 sec)

 MariaDB [(none)]> create database tcdb_production;
 Query OK, 1 row affected (0.00 sec)

 MariaDB [(none)]> GRANT ALL ON tcdb_production.* TO 'harshith'@'localhost' IDENTIFIED BY  'dbadmin';Query OK, 0 rows affected (0.00 sec)

  #Migration Of Database

  [harshith@localhost tcdb]$ rake db:migrate RAILS_ENV="production" --trace
  WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1
   ** Invoke db:migrate (first_time)
   ** Invoke environment (first_time)
   ** Execute environment
   ** Invoke db:load_config (first_time)
   ** Execute db:load_config
   ** Execute db:migrate
   ==  CreateProducts: migrating 
   -- create_table(:products)
   -> 0.0559s
   .
   .
    ==  AddSecondVersionIdToReports: migrated (0.0772s) 

    ** Invoke db:_dump (first_time)
    ** Execute db:_dump
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment 
    ** Invoke db:load_config 
    ** Execute db:schema:dump

    [harshith@localhost tcdb]$ clear

screenshot from 2014-06-27 00 22 31


#Trying to update settings table

MariaDB [(none)]> use tcdb_production; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A

Database changed MariaDB [tcdb_production]> update settings set value='Disabled' where name='Google Auth enabled'; Query OK, 0 rows affected (0.35 sec) Rows matched: 0 Changed: 0 Warnings: 0

MariaDB [tcdb_production]> select * from settings; Empty set (0.00 sec)

MariaDB [tcdb_production]> select * from users; Empty set (0.00 sec)

MariaDB [tcdb_production]> select * from versions; Empty set (0.00 sec)


 how to solve this, if there is any need for other information i'm happy to provide them .

Thanks harshith

harshith30 commented 10 years ago

Hi,

Since the Issue Mysql2::Error has been resolved , i'm going to close this issue , thanks for your help in solving it.

Thanks Harshith