Redmine installation issues rake command issue, MySQL database issue? - mysql

I have somewhat of a complex issue involving several different programs including redmine, MySQL, Ruby, Ruby on Rails etc. This is on Windows XP.
I am following the redmine instructions here: http://www.redmine.org/projects/redmine/wiki/RedmineInstall
I am on step 5. where I am suppose to type RAILS_ENV=production rake db:migrate
When I type this in the command prompt and hit enter I get an error: "RAILS_ENV" is not a command blah blah.
So I reorder it to: rake db:migrate RAILS_ENV=production
This seems to work correct, but I get the following:
C:\redmine-1.2.1>rake db:migrate RAILS_ENV=production --trace
* Invoke db:migrate (first_time)
* Invoke environment (first_time)
* Execute environment
rake aborted!
Access denied for user 'redmine'#'localhost' (using password: YES)
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:620:in `real_connect'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:620:in `connect'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:203:in `initialize'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:75:in `new'
Here is my database.yml file contents:
MySQL (default setup).
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: ****
encoding: utf8
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password:
encoding: utf8
# 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: redmine_test
host: localhost
username: root
password:
encoding: utf8
test_pgsql:
adapter: postgresql
database: redmine_test
host: localhost
username: postgres
password: "postgres"
test_sqlite3:
adapter: sqlite3
database: db/test.sqlite3
I really need some direction here. It's almost like there is a problem with my users/passwords. I have changed the passwords not to contain "!" or any other special characters. I do have capital and lower case letters.
Any help would be greatly appreciated.
DemiSheep

So, you have created the 'redmine' mysql user with the password specified in database.yml?
Can you connect to this user using mysql client? (e.g. mysql -uredmine -pyourmysqlpassword)
Does the user have all required privileges?

Related

How to have a mysql database in my production environment when deployed to Heroku

I have a Rails application that I've deployed to heroku, and I don't know how to have a mysql database for the production environment. (The mysql database for local environment is already created without a problem.)
Question1:
Here are some parts of heroku config. You can see below that CLEARDB_DATABASE_URL and DATABASE_URL share the same host, but the other parts are different. Which should be included in the production part of database.yml?
$ heroku config
=== exampleapp Config Vars
CLEARDB_DATABASE_URL:mysql://<username1>:<password1>#<host1>/<database1>?reconnect=true
DATABASE_URL:mysql2://<username2>:<password2>#<host1>/<database2>?reconnect=true
Here's my database.yml. (I've included the username, host and password of CLEARDB_DATABASE_URL.)
default: &default
pool: 5
timeout: 5000
development:
<<: *default
adapter: mysql2
database: exampleapp
pool: 5
timeout: 5000
username: root
password: xxx
host: localhost
production:
<<: *default
adapter: mysql2
database: exampleapp
username: <username1>
host: <host1>
password: <password1>
Question2:
I've run "heroku run rails db:migrate", but the tables weren't created, even though all the necessary migration files are created under db/migrate directory in my repository.
When I checked the mysql for heroku production environment (is this the right way to check it?), this is what happened;
$ mysql -u <username1> -p -h <host1> //username and host of CLEARDB_DATABASE_URL
$ mysql> show tables;
Empty set (0.18sec)
If I create the tables from scratch here using SQL, do they get linked to the app? (CREATE TABLE db_name.tbl_name (col_name data_type,...) etc.)
I have a whole set of database for local environment, so it'd be great if I can move the tables with the data inside to the production environment. Are there any ways I can do so?
For production systems it is best practice to pull the database information from environment variables rather than hardcoding them in config/database.yml. That's why the DATABASE_URL environment variable is set in Heroku. You can just access it in config/database.yml like this:
production:
<<: *default
adapter: mysql2
url: <%= ENV['DATABASE_URL'] %>
Second, db:migrate runs migrations against an existing database, but it doesn't create it. If you are using a version of Rails earlier than 6.0, there are three tasks to set up a new database:
% heroku run rails db:create
% heroku run rails db:schema:load
% heroku run rails db:seed
The db:create tasks creates the database, db:schema:load initializes your app's tables from db/schema.rb, and db:seed seeds the database using whatever you've put in db/seeds.rb
Rails 6+ adds a db:prepare task that rolls the creation tasks into one:
% heroku run rails db:prepare
As mentioned above. We shouldn't hard code database details in code As this information get updated in case of database upgrades by ClearDB. This should be pulled from environment variables. As from ENV its complete URL, We can extract details like below
require 'uri'
database_url = URI.parse(ENV['DATABASE_URL'])
user_info = database_url.userinfo.split(':')
default: &default
pool: 5
timeout: 5000
development:
<<: *default
adapter: mysql2
database: database_url.path[1..-1]
pool: 5
timeout: 5000
username: user_info.first
password: user_info.last
host: database_url.host
For the second question, Can you check your schema.rb. is it having all the tables required on production

Can't run rails "db: create" with remote ip on mysql

Here is the log
Can't connect to MySQL server on 'remote.ip.here.lol' (110)
Couldn't create 'solicit' database. Please check your configuration.
rails aborted!
Mysql2::Error: Can't connect to MySQL server on 'remote.ip.here.lol' (110)
bin/rails:4:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
my db.yml is like this:
default: &default
adapter: mysql2
encoding: utf8
database: db
host: remote.ip.here.lol
port: 3306
username: admin
password: supressed
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
test:
<<: *default
I don't have any clue of how to start, I recently got hired, my boss told about a gem dotenv-rails but I can't see how it fit to the current issue that I'm curently facing.
Edit: apparently using localhost and local database and user works fine, but not with the remote configuration.
Edit 2: I've created environment variables with dotenv and apparently I only need to fill a .env file with the needed information, it worked.
You might not have MySQL running on your machine? It seems you are trying to connect to your server but MySQL is not up.

rake db:migrate ignores host parameter for production

When I try to run rake db:migrate RAILS_ENV=production I get an error because it tries to connect to localhost (error: Mysql2::Error: Access denied for user 'xxxx'#'10.0.0.7' (using password: NO))
This is my database.yml file:
production:
adapter: mysql2
encoding: utf8
pool: 5
host: long-amazon-aws-rds-instance-endpoint
database: xxxx_production
username: xxxxx
password: <%= ENV['XXXX_DATABASE_PASSWORD'] %>
when I run echo $XXXX_DATABASE_PASSWORD it gives me the correct password and when I run a mysql -uxxxxx -hlong-amazon-aws-rds-instance-endpoint -p and then enter my password I can connect to the RDS no problem. I also have the environment variable set for passenger and the app connects fine to it, so the RDS instance is definitely reachable.
Why is rake trying to use the local ip and not the hostname specified in database.yml
So turns out you have to wrap the production in quotes. If I run rake db:migrate RAILS_ENV="production" it works...

How to connect Rails with MySQL? [duplicate]

This question already has answers here:
"Access Denied" when rails connects to Mysql
(3 answers)
Closed 8 years ago.
I have the following running correctly:
rails new simple
rails server (working)
rails generate controller demo index
mysql -u root -p and creating the database and assigning GRANT PRIVILIGES on the database is done.
Now the problem is, I used the Bitnami-RubyStack packages on my MAC 10.7. When I want to run rake db:schema:dump, I get this error:
bash-3.2$ rake db:schema:dump
rake aborted!
Access denied for user 'root'#'localhost' (using password: YES)
/Applications/rubystack-1.9.3-18/simple/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:dump => environment
(See full trace by running task with --trace)
even if I run GRANT PRIVILEGES.
Also I checked the username and password on my DB.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_development
pool: 5
username: root
password: something
socket: /tmp/mysql.sock
host: 127.0.0.1
In your database config
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_development
pool: 5
username: root
password: something
socket: /tmp/mysql.sock
host: 127.0.0.1
you should use either socket or host, not both. Since socket works for you (mysql -u root -p works), try using it with your app. If there's any permission problems or whatnot, you are going to have to create root#127.0.0.1 in your mysql console and use the host parameter.

rake db:multi:migrate DATABASE=configuration error with JRuby, mysql, riak

JRuby 1.7.1 and Rails 3.2.11
In terminal I'm running "rake db:multi:migrate DATABASE=configuration" but I keep getting the error below meaning as far as I can tell that the configuration database is not being created.
Connecting to database specified by database.yml
(4.0ms) SET SQL_AUTO_IS_NULL=0
rake aborted!
The driver encountered an unknown error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'configuration'
The specific steps I'm supposed to follow to get this set up are:
mysql.server start
mysql -uroot
create user 'funapp_test'#'localhost' IDENTIFIED BY 'funapp_test';
grant all privileges on *.* to 'funapp_test'#'localhost' with grant option;
create user 'funapp'#'localhost' IDENTIFIED BY '#sh4r3!';
grant all privileges on *.* to 'funapp'#'localhost' with grant option;
RAILS_ENV=test rake db:create
RAILS_ENV=development rake db:create
mysql -uroot funapp_test < db/structure.sql
mysql -uroot funapp < db/structure.sql
rake db:multi:migrate DATABASE=funapp
rake db:multi:migrate DATABASE=configuration
database.yml
development:
adapter: mysql
database: funapp
username: funapp
password: "#sh4r3!"
host: 127.0.0.1
pool: 5
xa: false
test: &test
adapter: mysql
database: funapp_test
username: funapp_test
password: "funapp_test"
host: 127.0.0.1
pool: 5
xa: false
configuration_development:
adapter: mysql
database: configuration
username: funapp
password: "#sh4r3!"
host: 127.0.0.1
pool: 5
xa: false
configuration_test:
adapter: mysql
database: configuration_test
username: funapp_test
password: "funapp_test"
host: 127.0.0.1
pool: 5
xa: false
Any ideas on what I can do to get this fixed? I've tried doing rake db:drop and rake db:migrate, as well as rake db:create:all (which gives me a Riak::Node configuration must include :source and :root keys. error) Thank you so much!
Figured it out, much simpler than I thought
mysql -uroot
create database configuration;
create database configuration_test;