简体   繁体   English

Rails:无法连接到远程MySQL数据库

[英]Rails: Cannot connect to remote MySQL database

I have problem with connection with my remote database. 我与远程数据库的连接有问题。

Steps, which i did: 步骤,我做了:

1) In GemFile added : 1)在GemFile中添加:

gem 'mysql2'

2) in database.yml: 2)在database.yml中:

development:
adapter: mysql2
database: myname
username: myuser
password: mypass
host: myhost.nazwa.pl
port: 3305 

3) then in console i typed: 3)然后在控制台中输入:

rake db:migrate

Communicat which i got: 我得到的Communicat:

Mysql2::Error: Can't connect to MySQL server on 'myhost.nazwa.pl' (4) Mysql2 :: Error:无法连接到“ myhost.nazwa.pl”上的MySQL服务器(4)

I wanted to try if I can connect with this database using small php script: 我想尝试一下是否可以使用小型php脚本与此数据库进行连接:

<?php 
$host = 'myhost.nazwa.pl';
$database = 'myname';
$username = 'myuser';
$password = 'mypass';

if ( mysql_connect($host,$username,$password) ) {
echo 'connect to mysql server *** ';
}

if ( mysql_select_db($database) ) {
echo 'open database';
}

if ( !mysql_close() ) {
echo 'cannot close connection';
exit (0);
}
?> 

And there is no problem. 而且没有问题。 I can connect, create tables, add data etc. 我可以连接,创建表,添加数据等。

Could you advise me something? 你能给我一些建议吗? Where can be problem? 哪里有问题? I will be very thankful. 我将非常感谢。 Regards :) 问候 :)

MySQL's default port is 3306 , and you've got 3305 in your configuration for some reason. MySQL的默认端口是3306 ,由于某种原因,您的配置中有3305。 Unless you're using a custom port, leave the port: argument out of your configuration file. 除非您使用自定义端口,否则将port:参数保留在配置文件之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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