How to access remote db data in Ruby on Rails? - mysql

I am having mysql in my local application and our client has given a sample application db access where we can find more seed data.
Now my question is there anyway of accessing the client data by changing any database.yml file in my local?
I tried using workbench -> Data export, I am getting the following error:
mysqldump: Got error: 1045:Access denied for user 'un'#ip-address (using
password: no) when trying to connect
Operation failed with exitcode 2
Is there any way to access the remote data without exporting?

you have to provide the ip address as host and all the login credentials to access it, also make sure you are inputting correct values. First check your connection by testing it on workbench then put values in yml file.
default: &default
adapter: mysql2
pool: 5
timeout: 5000
port: 3306
development:
<<: *default
database: <database name>
host: <ip address>
username: <username>
password: <password>
socket: <socket> or /tmp/mysql.sock

Related

Rails—mysqldump error when migrating

I'm using Rails 4.0, every time I run a migration I get this error:
mysqldump: Got error: 1045: Access denied for user 'regan'#'localhost' (using password: NO) when trying to connect
Could not dump the database structure. Make sure `mysqldump` is in your PATH and check the command output for warnings.
I think the migrations are still working ok, but I'm getting a lot of failing tests (I just received this project already built).
How do I fix this error?
I assume you don't have the users password setup in the database.yml file. The common scenario is that you setup a password in the mysql installation and now not providing it.
Your database.yml file should look some thing like this.
development:
adapter: mysql2
encoding: utf8
database: <my db>
username: <my user>
password: <my password>
host: localhost
port: 3306

Ruby Rails: Access denied for user 'root'#'localhost' (using password: YES)

I have read other questions similar to this one. I feel that my situation is different enough to ask again for extra possible problem.
I have a Ruby on Rails app all setup. I have set up other rails projects before, so I am somewhat familiar with doing rails. My specific problem with this error:
Access denied for user 'root'#'localhost' (using password: YES)
Here is my database.yml file
default: &default
adapter: mysql2
host: localhost
username: cmsapp
password: <%= ENV['CMSAPP_PASSWORD'] %> <-- this line is not working
port: 3306
pool: 5
timeout: 5000
development:
<<: *default
database: cms_dev
socket: /var/run/mysqld/mysqld.sock
production:
<<: *default
database: cms_prod
The problem I am having is: it seem to me that the password is not getting parsed or pulled from the ENV['CMSAPP_PASSWORD'] environment variable. I have double/triple check the password on the mysql db. If I put the literal password on the password: line,(which I am not supposed to do) it does connect. So I do know that the password is correctly set in mysql.
Ruby errors on this line:
connect user, pass, host, port, database, socket, flags
in the console at bottom of the page, I type in pass to see whats in the variable, and I get "<%= ENV[CMSAPP_PASSWORD] %>". if I type just 'ENV[CMSAPP_PASSWORD]' I get the correct password. So I know the right password is there, but I believe its sending the literal "<%= ENV[CMSAPP_PASSWORD] %>". So even though the correct password is in the environment variable, I still get the error: Access denied for user 'root'#'localhost' (using password: YES)
How do I troubleshoot weather the password is being properly extracted from the environment variable? Or how to figure out why it is not reading the environment variable?
Update 2016-06-09
I have switched back to the original mysql gem and all works as it is supposed to. I don't recommend anyone use the mysql2 gem. It DOES NOT have the database.yml file use environment variables. This is a security issue. I will not be using mysql2 gem until it can pull environment variables properly.
Thanks for any help.

Connecting remote database server in Rails app failed

Using Rails 3.2, mysql2 gem, MariaDB 5.5. I got the following error while trying to deploy the app for the first time:
Mysql2::Error: Access denied for user 'abc'#'%' to database 'app_production'
I'm not sure why the percent sign % in 'abc'#'%'.
Here's my database.yml:
production:
adapter: mysql2
encoding: utf8
reconnect: true
host: db.domain.com
port: 3306
database: app_production
pool: 5
username: abc
password: some_password_here
socket: /run/mysqld/mysqld.sock
My /etc/mysql/my.cnf has bind 0.0.0.0, firewall is temporarily disabled with sudo iptables -F.
This error due to permission on database access for the user, so you have to grant access permission for this user on above database. Find below command to grant permission. run these command on mysql terminal
GRANT ALL PRIVILEGES ON app_production.* TO 'abc'#'%' WITH GRANT OPTION
FLUSH PRIVILEGES
It sounds like the user abc is not set up with MySQL. Go to your MySQL client and make sure that user is created (with that database).

Rails Project Connection error with MySQL DB - Access Denied for root user

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

Heroku db:push Sequel::DatabaseConnectionError -> Mysql::Error: Access denied for user 'reg'#'localhost ' (using password: NO)

I have a problem using the heroku db:push command to transfer a MySQL database to heroku. I've tried using the same command for another app with a sqlite3 database and everything went fine.
C:\Users\reg\Team-Omni>heroku db:push
Loaded Taps v0.3.9
Auto-detected local database: mysql://127.0.0.1/omni_dev?encoding=utf8
Warning: Data in the app 'growing-mist-42' will be overwritten and will not be recoverable
.
Are you sure you wish to continue? (y/n)? y
Failed to connect to database:
Sequel::DatabaseConnectionError -> Mysql::Error: Access denied for user 'reg'#'localhost
' (using password: NO)
if i remove the password for the mysql anonymous account, the error changes to
Sequel::DatabaseConnectionError -> Mysql::Error: Access denied for user ''#'localhost' to database 'omni_dev'
--additional information--
my .gems file:
rails -v 2.3.8
andre-geokit --version 1.5.0 --source http://gems.github.com
You are getting that error because you are not specifying the password for the local database connection. Apparently the username is configured as 'reg' (maybe in the MySQL config file). This doesn't have anything to do with the Heroku PostgreSQL database, it's a problem connecting to your local MySQL database (named omni_dev).
Try the following connection string:
mysql://USERNAME:PASSWORD#127.0.0.1/omni_dev?encoding=utf8
for the appropriate values of USERNAME and PASSWORD.
I've had this problem as well, but I was passing a password. My local app worked fine, but when using heroku db:push, I got the same error as redge.
Adding a port in the database.yml fixed the problem. So, a working database.yml has the following entries:
database: DATABASE
username: USER
password: PASSWORD
adapter: mysql
encoding: utf8
socket: /Applications/MAMP/tmp/mysql/mysql.sock
port: 8889