In my project I have to connect my Rails app to old MySQL server(v4) with readonly access. I have third-party application there. Unfortunately I cannot change this situation.
The problem is when I try to connect there I get an exception:
ActionController:Variable 'sql_mode' can't be set to the value of 'STRICT_ALL_TABLES'
Here is my database.yml file
development:
adapter: mysql2
encoding: utf8
database: td
pool: 5
username: user
password: password
host: 10.12.12.12
I can connect to this DB with any DB client, but not with Rails app.
How to fix it?
Adding
strict: false
to the connector settings in database.yml solved the problem.
I get the following error, when trying to generate an app.
I have a database.yml with my db login info, but not sure what this error is exactly. Does anyone know what it is?
I assume it is verify login to the test db.
Make sure that your db username and password are configured for the development environment, not just the test environment. Initial rails application setup is there.
The test database is used by tests, such as rake spec or rake test and the development database is used when you are working with rails such as rails generate or rails console.
A typical setup is below:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: foo_development
pool: 5
username: db_username
password: db_password
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: foo_test
pool: 5
username: db_username
password: db_password
socket: /tmp/mysql.sock
Why do you want to have root user access your application?
It's recommended you create a different user and grant all privileges to this user and then configure your database.yml with those credentials.
I wanted to contribute my answer to this.
It sounds kind of amateur but it may help some poor chap that had the same issue as me.
I had my password in database.yml configured like this:
development:
<<: *default
database: my_db_name
username: my_username
password: !?my_password913
It's a rookie mistake but it screwed me up for a few minutes.
Ensure you wrap your password with quotes if you use special characters because ! for instance would evaluate as a boolean expression of false which would make mysql2 ignore the password field and send password=no
Thanks!
I'm having no end of trouble with my Rails 3 app's Mysql connection, though I have studied countless relevant threads. My error message:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect': Can't connect to MySQL server on 'localhost' (10061) (Mysql2::Error)
(Before you flag this as a duplicate question, consider whether you can find another thread with pertinent advice I have not followed.)
My efforts thus far:
I have copied the libmysql.dll file from <mysql installation>/bin to <ruby installation>/bin.
I have the mysql2 gem in the bundle, and it was installed with the connector (--with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32):
> bundle show mysql2
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32
I believe my database.yml file is configured correctly:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: tq_development
pool: 5
username: root
password: pinney
host: localhost
try replacing localhost with 127.0.0.1 (in workbench and yml)
Have you ran rake db:create yet on the project in question?
I agree with the above....Make sure it works with workbench or some other GUI tool and you can connect using the info the database.yml file.
If not....come back and give us another holler.
I get this error when running rails with mysql db. Basically it is not giving the root user access. I have no idea why this is and have been stuck with this for a while now.
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: YES)):
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack- 3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.7ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.7ms)
My Database.yml file is posted below for your reference. Im not sure how i check the password that MYSQL is automatically assigned to? Would it be my computer login password? Anyhow how do i check it. Also i cant simply type mysql on my command line i have to enter the entire path to access it. How do i change it. Most importantly i want to know how this access denied issue can be resolved. Thank you. Using mysql 5.5 on mac. x86_64 build.
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
# 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: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
Mysql uses the one that you've set on install. Sometimes it's empty.
Try mysql -u root. If it works - remove pass string form database yaml.
If it's not empty - https://stackoverflow.com/search?q=mysql+reset+password
I'm trying to get a rails app up and running on my computer, and I'm having issues with creating the databases. I've properly installed/setup rails, mysql and have installed the mysql 2.8.1 gem (I verified this with gem list).
So now, I'm trying to run 'rake db:create:all' and I'm getting the following error:
Couldn't create database for
{"encoding"=>"utf8",
"username"=>"root",
"adapter"=>"mysql", "database"=>"pyo",
"host"=>"localhost", "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)
Couldn't create database for
{"encoding"=>"utf8",
"username"=>"root",
"adapter"=>"mysql",
"database"=>"pyo_test",
"host"=>"localhost", "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)
I'm currently running 5.5.10 MySQL Community Server (GPL) on Snow Leopard (10.6.6)
And here is what is in my database.yml file
development:
adapter: mysql
encoding: utf8
database: pyo
username: root
password:
socket: /tmp/mysql.sock
host: localhost
test:
adapter: mysql
encoding: utf8
database: pyo_test
username: root
password:
socket: /tmp/mysql.sock
host: localhost
I notice how the end of the error says "charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)" -- Is that the issue? And if so, how do I fix it?
I've been stuck on this thing for hours and can't find anything that helps on Google. So any help at this point would be much appreciated.
Thanks!!
I know this thread is old but being a IT guy who believes in keeping good solid documentation in one place here goes:
The problem actually stems from your "config/database.yml" file. You are pointing ROR to the wrong location for the MySQL Socket.
I ran into this problem and what it turned out to be is the gem was built on a mac system and the developer did not account for other operating systems by putting his "mysql.sock" file in the "/tmp" directory rather than the "/var/run/mysqld/mysqld.sock" .
So his "database.yml" file looked like:
development:
adapter: mysql2
#encoding: utf8
database: somedatabase
pool: 5
username: someusername
password: somepassword
socket: /tmp/mysql.sock
Because I was on a Ubuntu System I had to change mine to the following:
development:
adapter: mysql2
#encoding: utf8
database: somedatabase
pool: 5
username: someusername
password: somepassword
socket: /var/run/mysqld/mysqld.sock
Yes the error can be misleading however it has nothing to do with your "encoding" or whether you are using localhost or 127.0.0.1 (At least in linux/UNIX systems these translate to the same thing and are synonymous)
Begin Edit
Also it is not good to have encoding commented out like I do above. So I am providing the modification here for reference.
development:
adapter: mysql2
encoding: utf8
database: somedatabase
pool: 5
username: someusername
password: somepassword
socket: /var/run/mysqld/mysqld.sock
End Edit
think I had something like this...fixed by adding this to database.yml:
host: 127.0.0.1
Or in your case, changing it from localhost.
I was getting the same issue with the mysql2 gem. Then I found my MySQL is listening in 'localhost' only and not '127.0.0.1', so I changed it to 'localhost' and now I don't get that issue anymore. Everything works now.
So, after about 3 or 4 days of googling and trying so many different things, I stumbled on this somehow:
http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/
And guess what? IT WORKS! PERFECTLY. Which leads me to believe that the problem lies within MySQL 5.5.10. Something about it will not just play nice with my ruby/rails environment. However, once I followed the instructions on the link above (which include uninstalling mysql and re-installing 5.1), my app now runs perfectly on my local machine.
Hope this helps someone!
I want to share my solution.
I had my database.yml as follow
default: &default
adapter: mysql2
encoding: utf8
username: root
password:
host: 127.0.0.1
port: 3306
development:
<<: *default
database: dev.database
My mistake was in this line
database: dev.database
So, I write without (.)
database: devdatabase