Gangmax Blog

自由之思想,独立之精神

Rails MySQL Connection Problem

| Comments

From here, here and here.

When using MySql with Rails, it runs properly when Rails and MySql are on the same computer, but running Rails from another computer which connects the MySql remotely get conection problem. Here is the solution.

  1. Modify the “/etc/mysql/my.cnf” file by commenting the content:
1
2
skip-networking
bind-address          = 127.0.0.1

Then restart the MySql service by executing “service mysql stop; service mysql start”.

  1. Still cannot connection the MySql server, error message is “host ‘xxx’ is not allowed to connect to this MySQL server”, login the MySql server from the server it is and run the following command:
1
2
mysql -u root -pPassw0rd
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

Then it works.

P.S.

Some usefull statements:

1
2
3
4
5
6
7
-- Create new account in MySQL:
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
-- Create new account from all host:
CREATE USER 'jeffrey'@'%' IDENTIFIED BY 'mypass';
-- Give full access to one database to an account(this statement
-- will create the account as well if it's not existing):
GRANT ALL PRIVILEGES ON elink.* To 'username'@'%' IDENTIFIED BY 'password';

Comments