I'm following a basic tutorial in Linda.
I have been able to install everything properly now, but when I start my Rails server I get this message when I visit localhost:3000:
Unknown database 'simple_cms_development'
and then
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (23.5ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (29.8ms)
Have you created the database in MySQL? You should be able to run rake db:create and have Rails create it for you.
I had the same error, please run the following command on the Command Prompt:
rake db:create
to solve the problem.
Look for the answers of these questions:
Have you installed the mysql2 gem?
Is it mentioned in your Gemfile?
Did you run the command rake db:create ?
Sometimes creating database with rake causes issues.
You can also create the database inside mysql
Make sure mysql is in the root %PATH% in command prompt type echo %PATH% to check.
If it isn't in your PATH. Then do a quick google search on windows PATH to get instructions
Open command prompt
type mysql -u root -p
type your password that you created for your root
To create database
create database simple_cms_development
done
was getting the same error but caused was different
Mysql2::Error: Unknown database 'rdddd_development'
/Users/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in connect'
/Users/commeasure/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:ininitialize
faced this error due to the created method dynamically, code is here
Role.all.map(&:name).map(&:parameterize).map(&:underscore).each do |name|
define_method("#{name.to_sym}?") do
role.name == name.upcase
end
end
How do I fix this for the temporary purpose just comment it out
Related
Here is one of my problematic builds:
https://travis-ci.org/RailsEventStore/rails_event_store_active_record/jobs/268876871
Here is the error:
Mysql2::Error:
Access denied for user 'travis'#'%'
to database 'rails_event_store_active_record'
and here is a list of connection strings that I tried
DATABASE_URL=mysql2://travis:#127.0.0.1/rails_event_store_active_record?pool=5
DATABASE_URL=mysql2://travis#127.0.0.1/rails_event_store_active_record?pool=5
DATABASE_URL=mysql2://travis#localhost/rails_event_store_active_record?pool=5
This is how I create the DB:
before_script:
- mysql -e 'CREATE DATABASE rails_event_store_active_record;'
And the code responsible for connecting:
ENV['DATABASE_URL'] ||= "postgres://localhost/rails_event_store_active_record?pool=5"
RSpec.configure do |config|
config.failure_color = :magenta
config.around(:each) do |example|
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
Everything works fine when I test my gem with Postgresql but it fails for Mysql.
https://docs.travis-ci.com/user/database-setup/#MySQL - documents how to connect to MySQL DB and I am not sure what I am doing wrong right now.
I just tried one more option and it worked. Apparently I had to use root user instead of travis despite what the documentation says...
DATABASE_URL=mysql2://root:#127.0.0.1/rails_event_store_active_record?pool=5
In my rails app I have this configuration for database
adapter: mysql2
host: *****
username: *****
password: <%= ENV['MYSQL_PW'] %>
database: *****
encoding: utf8
timeout: 5000
pool: 5
It is working perfectly in the server. But recently there was a bug and I tried to access rails console, but I get this error
Access denied for user '****' (using password: NO) (Mysql2::Error).
I also I tried to run migration and I get same error again. I don't understand what is the problem here. How can I solve this?
Also how can I check if ENV['MYSQL_PW'] is set in the unix environment variable?
Here is my log
$ rake db:migrate
DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in <top (required)> at )
DEPRECATION WARNING: You did not specify a `log_level` in `production.rb`. Currently, the default value for `log_level` is `:info` for the production environment and `:debug` in all other environments. In Rails 5 the default value will be unified to `:debug` across all environments. To preserve the current setting, add the following line to your `production.rb`:
config.log_level = :info
. (called from block in tsort_each )
rake aborted!
Mysql2::Error: Access denied for user '****' (using password: NO)
Don't forget to specify RAILS_ENV when you are running your commands.
By default rails assumes the environment is development, but as I see here you want to run those on production.
Simply do
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rails c
# or alternatively
rails c -e production
http://guides.rubyonrails.org/command_line.html
Try the following:
Edit database.yml password to be a string and not an ENV variable, to identify the problem.
To test the ENV Variable, log in the rails console with rails c and input ENV['YourVariable'] to see if it is set
You can solve this problem by sourcing your bash_profile file if you have Unix system (linux/ubuntu/mac) in the terminal input source ~/.bash_profile
If you have Rails 4 upon you should run the following terminal command spring stop
In database.yml you should include the ENV Variable with the following syntax, beacuse yml needs the .erb syntax. <%= ENV['YOUR VARIABLE'] %>
Failing to access environment variables within `database.yml` file
The ENV Variable is Case Sensitive
I had this problems and I was able to solve it, but I keep having them. For this reason I read several discussions:
Rails 4.1 environment variables not reloading
Sorry if I was not able to help more
Fabrizio Bertoglio
I connect my Rails app to MySQL database, working with that and after turning off the laptop and starting Rails and MySQL server again, I get the error
ActionView::Template::Error (Mysql2::Error: Table 'database.table' doesn't exist: SHOW FULL FIELDS FROM `table`):
This is in Rails log.
When I log in into MySQL through the terminal
mysql -u root -p
choose a database and then try to display data from a table, like
mysql> select * from users;
ERROR 1146 (42S02): Table 'database.users' doesn't exist
I google this issue and found a temporarily solution, but this is not appropriate because it involves remove all old data in the respective database:
cd /usr/local/mysql/data
sudo rm -rf database_name
So I would like to ask you for help - how to properly figure out this issue?
Thank you
Looks like you're using rails, did you issue the command
rake db:migrate
And while you're in mysql I suggest you to get the list of available tables with:
show tables;
I have an rails application with an mySQL database and not the permission to change the database password of the user. The problem is that the password contains a mutated vowel like: asÖs8ss when I try to run rake db:migrate the migration fails with this error:
rake aborted!
special characters are not allowed
I tried to escape the Ö in this ways:
\xC3\x96
\u00D6
But this doesn't help. I also added encoding: UTF8 to the database connection and #encoding: utf-8 to the top of the database.yml but nothing helps to solve my problem.
Has anyone an idea how to escape the Ö right or to fix this somehow?
UPDATE I am using JRuby, if this help?
After I updated to the newest version of JRuby and run bundle update I got it to work. Also you have to make sure, all your files are utf-8 on my windows machine I had to configure my editor, because default was ANSI.
I need to run db:migrate with this command:
jruby -J-Dfile.encoding=UTF-8 -S rake db:migrate RAILS_ENV=production
I am using Rails v2.3.2 with MySQL v5.1 and mysql2 gem.
I run the following rake tasks in a method like:
def db_operation
Rake::Task['db:drop'].invoke #this one does not work
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
...
end
but Rake::Task['db:drop'].invoke does not drop my database**, and there is no error message which makes me have no clue to find the reason.
Then:
I go to MySQL command-line to execute "DROP DATABASE my_db;" , it raise me the following error message:
ERROR 1010 (HY000): Error dropping database (can't rmdir './my_db/', errno: 17)
After that:
I run above code again, the database surprisingly get dropped...
What was happening?? Why my rake db:drop does not drop database, but after I run drop command on MySQL command-line and run rake db:drop again, it get dropped??? (and I got error when I run on MySQL command-line)
P.S.
rake db:create and rake db:migrate are working without problem.
Refer this LINK
you might be having files in /var/lib/mysql/my_db/ that mysql didn't create.
Try listing those files and see what's there. Try moving anything there to a temporary directory (or deleting if you're really sure you won't need them), then try again.