首页 \ 问答 \ java.sql.SQLException:访问被拒绝,用户'root'@172.17.0.1'(使用密码:YES)(java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES))

java.sql.SQLException:访问被拒绝,用户'root'@172.17.0.1'(使用密码:YES)(java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES))

我想从Java写入一个MySQL数据库,但我得到这个错误:

java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES)

我连接到本地的mysql实例,说实话我不知道172.17.0.1 ip是什么。

我写的小码:

public static void writeToDB(String value, String unit) throws ClassNotFoundException, SQLException, SQLException
{

    // create a mysql database connection
    String myDriver = "com.mysql.cj.jdbc.Driver";
    String myUrl = "jdbc:mysql://localhost:3306/MyDB";
    Class.forName(myDriver);

    Connection conn = null;

    conn = DriverManager.getConnection(myUrl, "root", "MyPass");


    // the mysql insert statement
    String query = " insert into data (unit, value)"
            + " values (?, ?)";

    // create the mysql insert preparedstatement
    PreparedStatement preparedStmt = null;
    preparedStmt = conn.prepareStatement(query);
    preparedStmt.setString (1, unit);
    preparedStmt.setString (2, value);

    // execute the preparedstatement
    preparedStmt.execute();
    conn.close();

}

我跑了

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyPass' WITH GRANT OPTION;

但没有任何改变。

我的my.cnf全部注释掉了。 我的本地IP地址是192.168.1.46。 我试图在myUrl变量上使用这个ip和127.0.0.1来代替localhost,但没有任何改变。

我重启了mysql服务器,eclipse和pc都没有成功。

编辑:其他信息我停止了服务器并运行代码。 我得到完全相同的例外。 我猜想我根本无法到达服务器。

我可以在我的Python脚本中使用“localhost”。 它在与java代码相同的表上写入。


I am trying to write into a mysql database from Java but I get this error:

java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES)

I am connecting to a local mysql instance and to be honest I don't know what's 172.17.0.1 ip.

The small code I wrote:

public static void writeToDB(String value, String unit) throws ClassNotFoundException, SQLException, SQLException
{

    // create a mysql database connection
    String myDriver = "com.mysql.cj.jdbc.Driver";
    String myUrl = "jdbc:mysql://localhost:3306/MyDB";
    Class.forName(myDriver);

    Connection conn = null;

    conn = DriverManager.getConnection(myUrl, "root", "MyPass");


    // the mysql insert statement
    String query = " insert into data (unit, value)"
            + " values (?, ?)";

    // create the mysql insert preparedstatement
    PreparedStatement preparedStmt = null;
    preparedStmt = conn.prepareStatement(query);
    preparedStmt.setString (1, unit);
    preparedStmt.setString (2, value);

    // execute the preparedstatement
    preparedStmt.execute();
    conn.close();

}

I ran

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyPass' WITH GRANT OPTION;

but nothing changed.

My my.cnf is all commented out. My local ip is 192.168.1.46. I tried to use this ip and 127.0.0.1 instead of localhost on the myUrl variable but nothing changed.

I restarted the mysql server, eclipse and pc without success.

Edit: additional info I stopped the server and ran the code. I get the exact same exception. I guess somehow I can't reach the server at all.

I am able to use "localhost" in my Python script. It writes on the same table as the java code.


原文:https://stackoverflow.com/questions/43673461
更新时间:2022-06-26 12:06

最满意答案

git filter-branch树过滤git filter-branch本质上很慢。 它的工作原理是将每个提交提取到一个临时目录中的完整树中,让您更改每个文件,然后找出您更改的内容并从您留下的每个文件中进行新的提交。

如果您通过快速导出/快速导入导出和导入, 那么就是转换数据的时间:在将文件写入内容之前,您已将文件的扩展数据存储在内存中,但不是文件系统形式。出口/进口管道。 而且, git fast-import本身就是一个shell脚本,因此在那里插入过滤是微不足道的,而hg-fast-export是一个Python程序,因此在那里插入过滤也很简单。 显而易见的地方就在这里 :只需重新编码d


A tree filter in git filter-branch is inherently slow. It works by extracting every commit into a full blown tree in a temporary directory, letting you change every file, and then figuring out what you changed and making the new commit from every file you left behind.

If you're exporting and importing through fast-export / fast-import, that would be the time to convert the data: you have the expanded data of the file in memory, but not in file-system form, before writing it to the export/import pipeline. Moreover, git fast-import itself is a shell script so it's trivial to insert filtering there, and hg-fast-export is a Python program so it's trivial to insert filtering there as well. The obvious place would be here: just re-encode d.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。