首页新闻找找看学习计划

mysql连接报错:ERROR 2002 (HY000):Can't connect to MySQL server on '172.18.0.4' (115)

0
悬赏园豆:10 [已解决问题] 解决于 2019-11-14 09:27

使用MySQL客户端连接远程amoeba进行远程控制数据库报错:

root@uduntu:~# mysql -u root -P8066  -h 172.18.0.4 -p
Enter password: 
ERROR 2002 (HY000): Can't connect to MySQL server on '172.18.0.4' (115)

求解答????在线等谢谢,可进行远程协调

问题补充:

下面是amoeba.xml配置

<?xml version="1.0" encoding="gbk"?>

<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
<amoeba:configuration xmlns:amoeba="http://amoeba.meidusa.com/">

    <server>
        <!-- proxy server绑定的端口 -->
        <property name="port">8066</property>
        
        <!-- proxy server绑定的IP -->
        <property name="ipAddress">127.0.0.1</property>
        
        <!-- proxy server net IO Read thread size -->
        <property name="readThreadPoolSize">100</property>
        
        <!-- proxy server client process thread size -->
        <property name="clientSideThreadPoolSize">80</property>
        
        <!-- mysql server data packet process thread size -->
        <property name="serverSideThreadPoolSize">100</property>
        
        <!-- socket Send and receive BufferSize(unit:K)  -->
        <property name="netBufferSize">100</property>
        
        <!-- Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). -->
        <property name="tcpNoDelay">false</property>
        
        <!-- 对外验证的用户名 -->
        <property name="user">root</property>
        
        <!-- 对外验证的密码 -->
        
        <property name="password">redhat</property>
    
    </server>
    
    <!-- 
        每个ConnectionManager都将作为一个线程启动。
        manager负责Connection IO读写/死亡检测
    -->
    <connectionManagerList>
        <connectionManager name="defaultManager">
            <className>com.meidusa.amoeba.net.AuthingableConnectionManager</className>
        </connectionManager>
    </connectionManagerList>
    
    <dbServerList>
        <!-- 
            一台mysqlServer 需要配置一个pool,
            如果多台 平等的mysql需要进行loadBalance, 
            平台已经提供一个具有负载均衡能力的objectPool:com.meidusa.amoeba.mysql.server.MultipleServerPool
            简单的配置是属性加上 virtual="true",该Pool 不允许配置factoryConfig
            或者自己写一个ObjectPool。
        -->
        <dbServer name="server1">
            
            <!-- PoolableObjectFactory实现类 -->
            <factoryConfig>
                <className>com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory</className>
                <property name="manager">defaultManager</property>
                
                <!-- 真实mysql数据库端口 -->
                <property name="port">3306</property>
                
                <!-- 真实mysql数据库IP -->
                <property name="ipAddress">172.18.0.2</property>
                <property name="schema">test</property>
                
                <!-- 用于登陆mysql的用户名 -->
                <property name="user">jia</property>
                
                <!-- 用于登陆mysql的密码 -->
                
                
                <property name="password">redhat</property>
                
                
            </factoryConfig>
            
            <!-- ObjectPool实现类 -->
            <poolConfig>
                <className>com.meidusa.amoeba.net.poolable.PoolableObjectPool</className>
                <property name="maxActive">200</property>
                <property name="maxIdle">200</property>
                <property name="minIdle">10</property>
                <property name="minEvictableIdleTimeMillis">600000</property>
                <property name="timeBetweenEvictionRunsMillis">600000</property>
                <property name="testOnBorrow">true</property>
                <property name="testWhileIdle">true</property>
            </poolConfig>
        </dbServer>
        
        
        <dbServer name="multiPool" virtual="true">
            <poolConfig>
                <className>com.meidusa.amoeba.server.MultipleServerPool</className>
                <!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED -->
                <property name="loadbalance">1</property>
                
                <!-- 参与该pool负载均衡的poolName列表以逗号分割 -->
                <property name="poolNames">server1</property>
            </poolConfig>
        </dbServer>
        
    </dbServerList>
    
    <queryRouter>
        <className>com.meidusa.amoeba.mysql.parser.MysqlQueryRouter</className>
        <property name="ruleConfig">${amoeba.home}/conf/rule.xml</property>
        <property name="functionConfig">${amoeba.home}/conf/functionMap.xml</property>
        <property name="ruleFunctionConfig">${amoeba.home}/conf/ruleFunctionMap.xml</property>
        <property name="LRUMapSize">1500</property>
        <property name="defaultPool">server1</property>
        
        <!--
        <property name="writePool">server1</property>
        <property name="readPool">server1</property>
        -->
        <property name="needParse">true</property>
    </queryRouter>
</amoeba:configuration>
避凉闲庭的主页 避凉闲庭 | 菜鸟二级 | 园豆:349
提问于:2019-11-12 16:51
< >
分享
最佳答案
0

Maybe the root is not allowed to connect mysql server from a remoting host. I advise you to create a new user instead of root.

create user 'joey'@'%' identified by 'yourpassword';
grant all privileges on yourdb.* to 'joey'@'%'

you can replace '%' with your host(if not, connecting mysql server from every remoting host is allowed)

收获园豆:10
会长 | 大侠五级 |园豆:5630 | 2019-11-12 17:33

The user used for the connection is not the root of the real database, but the connection user created above Amoeba  Thank you

避凉闲庭 | 园豆:349 (菜鸟二级) | 2019-11-12 17:49
其他回答(1)
0

要检查下 mysql服务是否开了远程权限

ycyzharry | 园豆:18844 (专家六级) | 2019-11-12 21:54

检查过了,不经过amoeba是可以正常访问数据库的

支持(0) 反对(0) 避凉闲庭 | 园豆:349 (菜鸟二级) | 2019-11-12 22:03

@避凉闲庭: 是不是数据库的访问权限没有对 amoeba 所在的服务器开启,导致amoeba无法访问数据库
解决方案:去主数据库和从数据库进入mysql 并输入以下命令

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘密码‘ WITH GRANT OPTION;
支持(0) 反对(0) ycyzharry | 园豆:18844 (专家六级) | 2019-11-12 22:11

@ycyzharry: 单独使用amoeba服务器访问数据库是可以链接访问的,但是加入了amoeba就无法访问了

支持(0) 反对(0) 避凉闲庭 | 园豆:349 (菜鸟二级) | 2019-11-13 06:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册