简体   繁体   English

如何在Centos中使用MySql连接到远程服务器?

[英]How to connect to remote server using MySql in Centos?

I am new to hadoop. 我是hadoop的新手。 I am practicing hadoop on cloudera environment. 我正在cloudera环境上练习hadoop。 I am trying to connect to remote server using mySql (which is pre-installed in cloudera), but it's not connecting. 我正在尝试使用mySql(已预安装在cloudera中)连接到远程服务器,但未连接。

Actually my main intention is to run a job by importing data from remote server using Sqoop and to store it in HDFS location. 实际上,我的主要目的是通过使用Sqoop从远程服务器导入数据来运行作业并将其存储在HDFS位置。 But getting error as 但是得到错误

Communication link failure

So, first I am trying to connect with the help of mySql, but here also getting error as unable to connect to server. 因此,首先,我尝试在mySql的帮助下进行连接,但由于无法连接到服务器,这里也会出现错误。

mysql -u "username" -h "xxx.xxx.xx.xxx(ip address)" -p

It's not connecting. 没有连接。 give error message as 给出错误信息为

Error: Unable to connect to mysql server "xxx.xx.xxx.xx"

If I am trying to connect to localhost it's working good, 如果我尝试连接到本地主机,则工作正常,

mysql -u root -p

Should I need to do any changes in config files to connect to remote server for importing of data from database to HDFS via Sqoop. 我是否需要对配置文件进行任何更改以连接到远程服务器,以便通过Sqoop将数据从数据库导入到HDFS。

Can anyone please suggest me how to connect to remote server by using mysql from centOs - Cloudera environment. 任何人都可以建议我如何通过centOs-Cloudera环境使用mysql连接到远程服务器。

If I understood correctly: 如果我正确理解:

  • when you are connecting to your MySQL server locally with mysql -u root -p it works 当您使用mysql -u root -p在本地连接到MySQL服务器时,它可以工作
  • when you are connecting to the same server from a remote server it does not works 当您从远程服务器连接到同一服务器时,它不起作用

If this is your issue you most likely need to edit the file /etc/mysql/my.cnf on the MySQL server and add the public server IP in bind-address=[public_ip] and restart MySQL. 如果这是您的问题,则您很可能需要在MySQL服务器上编辑文件/etc/mysql/my.cnf ,并在bind-address=[public_ip]添加公共服务器IP,然后重新启动MySQL。

You also need to ensure your user is allowed to access the server remotely or you will have to create a remote user. 您还需要确保允许您的用户远程访问服务器,否则您将必须创建一个远程用户。 You can see users and their allowed origin from: 您可以从以下位置查看用户及其允许的来源:

SELECT Host, User FROM mysql.user;

Finally you might have a firewall (like ufw ) on your server preventing you from accessing the MySQL port (by default 3306 ) remotely. 最后,您的服务器上可能有防火墙(如ufw ),阻止您远程访问MySQL端口(默认为3306 )。 If this is the case, you need to allow connections from your remote server in your firewall. 在这种情况下,您需要允许防火墙中的远程服务器进行连接。

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

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