简体   繁体   中英

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM