【问题标题】:Ant couldn't connect to mysql (access denied), but mysql client couldAnt 无法连接到 mysql(访问被拒绝),但 mysql 客户端可以
【发布时间】:2010-10-27 08:54:37
【问题描述】:

我的 ant 文件中有下一个任务:

<target name="initdb">  
  <sql driver="com.mysql.jdbc.Driver"
       url="jdbc:mysql://localhost:3306/dtest"
       userid="root" password="oksaoksaoksa" >
    <classpath>
      <pathelement path="./lib/mysql-connector-java-5.1.13-bin.jar"/>      
    </classpath>
    <transaction  src="./init.sql"/>
  </sql>
</target>

当我运行它时,我看到了错误:

BUILD FAILED
/home/sbos/projects/texterra-tests/deploy.xml:43: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

但是,我可以使用 mysql 客户端使用这样的登录名和密码登录:

mysql -u root -p
Enter password: <oksaoksaoksa>
Welcome to the MySQL monitor.  Commands end with ; or \g.
...

为什么会这样?如果这很重要,我刚刚在 ubuntu 10.10 中安装了 mysql

【问题讨论】:

  • 检查端口,是不是只配置了默认3306?

标签: mysql ant


【解决方案1】:

这是因为当你在mysql客户端通过localhost连接时,它使用unix socket连接,处理权限有点不同,而ant通过tcp/ip连接到localhost。

尝试授予对 127.0.0.1 的访问权限(就 mysql 服务器而言,它与 localhost 不同)

grant all on initdb.* to 'root'@'127.0.0.1' identified by 'oksaoksaoksa';

【讨论】:

    猜你喜欢
    • 2018-02-05
    • 1970-01-01
    • 2015-06-21
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多