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
Related
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'm a new Rails Developer, and I'm working on a legacy Rails app. Whenever I run the rake db:create command, I get an error that the database couldn't be created. I have found many StackOverflow questions related to this, but in troubleshooting nearly all permutations of solutions, I couldn't resolve the issue.
I created the three Dbs (dev, prod, test), created the user with all access privileges to these dbs, and ran rake db:create.
I'm running Mac OS X Lion, MySQL 5.5.28, Rails 2.3.5, Ruby 1.8.7. Here are my settings
development:
adapter: mysql
encoding: utf8
database: adva_development
username: adva
password: ****
host: localhost
socket: /tmp/mysql.sock
Here's the error:
Couldn't create database for {"adapter"=>"mysql", "username"=>"adva", "host"=>"localhost", "encoding"=>"utf8", "database"=>"adva_development", "socket"=>"/tmp/mysql.sock", "password"=>"****"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)
I have done the following troubleshooting:
Verified user and password are correct, and the user has access to the DB. (Double checked user access with SELECT * FROM mysql.db WHERE Db = 'adva_development' \G; User has all privileges.)
Verify the socket is correct. I don't really understand sockets, but I can plainly see it at /tmp/mysql.sock.
Checked collation and character set. I found out I had created the DB in latin charset and collation, so I recreated them. I ran show variables like "collation_database"; and show variables like "character_set_database"; and came back with utf8 and utf8_unicode_ci respectively.
I followed the instructions in this question. After uninstalling mysql gem, I ran the following but came up with the same error:
gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql-5.5.28-osx10.6-x86_64/bin --with-mysql-config=/usr/local/mysql-5.5.28-osx10.6-x86_64/bin/mysql_config
Following Matt's suggestion, here's what a rake --trace db:create reveals:
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
Couldn't create database for {"database"=>"adva_development", "adapter"=>"mysql", "host"=>"127.0.0.1", "password"=>"woof2adva", "username"=>"adva", "encoding"=>"utf8"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)
After 3 days and six or seven hours, I have pretty much run out of options. I tried various random things, like replacing localhost with 127.0.0.1 to no avail.
Could there be something wrong related to my specific environment? Mac OS X Lion + MySQL 5.5.28? I plan on trying on setting up everything in a Linux environment.
Thanks!
You can try changing localhost to 127.0.0.1 and removing socket to use TCP/IP instead of a local socket.
Or try to verify if your database server uses the same socket as Rails:
mysqladmin variables | grep socket
If this doesn't help, then try to connect to the database server with pure Ruby and create a new database:
require 'rubygems'
require 'mysql'
begin
db = Mysql.new('localhost', 'root', 'yourpassword')
db.query('create database sample_database;');
rescue Mysql::Error => e
puts e
ensure
db.close unless db.nil?
end
and see if this runs. You should have mysql gem installed (gem install mysql)
Make sure you running a more recent version of the mysql gem. I ran into this problem with version 2.8. Upgrading to 2.9 fixed the issue.
change 'localhost' into '127.0.0.1' (loop back address) , hope its works
I am having trouble in rails, I have just installed it but when I update after updating mysql settings and running
rake db:create
and then
rails server
It started server and then when I tried viewing it via browser there errors saying active record connection not established error in strange way. I am new to both ruby and rails so that's why not understanding by debugging info. I assume that there is some thing wrong in MySQL configuration. I am using it on windows and using railsinstaller and using MySQL that came with XAMPP.
So can anyone tell that what is wrong with it and how can it be solved? Or is it better to use Linux for RoR? I do many things on windows thats why if there will be some solution at windows then that would be helpeful.
thanks for your time, following is attached output image.
I also observed that rake db:create command is not creating db, I had to do this manually. Following is my configurations for db:
adapter:mysql2
host:localhost
encoding:utf8
database:kaasib_new
pool:5
username:root
password:~
So is this fine? I don't have password on local machine db and do I need to mention 3306 for mysql in it?
A couple of things to try:
If the tilde character in the password field above is a typo, ok,
but there shouldn't be anything there.
Not sure if it's a function
of posting here, but Whitespace matters in YAML files. It should be
set up with indents like below (socket is optional):
.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: app_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Open Gemfile from your project.
add line => gem 'mysql2'
run command => bundle update
restart your server.
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
So I thought I had fixed the problem posted in this question and I uninstalled Rails 3.0.0 with sudo gem uninstall rails -v 3.0.0, but then I had troubles with other things. I took rogerdpack's advice to a different level and uninstalled all of my ruby gems and mysql, then reinstalled them. Now I get the following:
Icarus:temporary atg$ rails shopping -d mysql
create ........
Icarus:temporary atg$ cd shopping/
Icarus:shopping atg$ rake db:create
(in /Users/atg/temporary/shopping)
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"shopping_development", "pool"=>5, "password"=>nil, "socket"=>"/tmp/mysql.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)
What does this mean and how can I fix it?
All help is appreciated and thanks in advance!
I restarted after the install and everything worked again. So the key fix was to uninstall and reinstall everything, and then to restart so that changes can take effect.