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
最满意答案
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, andhg-fast-export
is a Python program so it's trivial to insert filtering there as well. The obvious place would be here: just re-encoded
.
相关问答
更多-
我在编码级别尝试了很多东西。 没有工作。 最后,我尝试了Berger的建议,将源代码编码格式更改为UTF-8,然后使用UTF-8构建一切正常。 只有我必须保持注意力的是项目中使用的特殊字符。 只要项目级别的编码已更改,特殊字符更改为? 符号。 我需要转换所有这些? 到实际的特殊字符。 这是我需要花费的唯一努力。 这对于开发者来说可能是一个混乱的情况,但是对于开发者/项目来说这是一次性活动,所以这应该是可以的。 感谢伯杰的建议。 I tried multiple things on the encoding ...
-
git filter-branch树过滤git filter-branch本质上很慢。 它的工作原理是将每个提交提取到一个临时目录中的完整树中,让您更改每个文件,然后找出您更改的内容并从您留下的每个文件中进行新的提交。 如果您通过快速导出/快速导入导出和导入, 那么就是转换数据的时间:在将文件写入内容之前,您已将文件的扩展数据存储在内存中,但不是文件系统形式。出口/进口管道。 而且, git fast-import本身就是一个shell脚本,因此在那里插入过滤是微不足道的,而hg-fast-export是一 ...
-
ISO-8859-1与UTF-8?(ISO-8859-1 vs UTF-8?)[2021-11-30]
Unicode正在接管,已经超越了其他所有。 我建议你现在跳上火车。 请注意,unicode有几种口味。 Joel Spolsky概述 。 (截至2012年2月的图表显示,请参阅下面的注释获取更多精确值。) Unicode is taking over and has already surpassed all others. I suggest you hop on the train right now. Note that there are several flavors of unicode. J ... -
欧元符号不在ISO-8859-1中。 (ISO-8859-15是为此目的而创建的。) 最好我回忆mb_convert_encoding() , mb_convert_encoding()不会音译mb_convert_encoding() 。 考虑使用iconv()代替。 和/或确保根据需要设置content-type标题。 在下一个PHP版本中,还会有包装ICU的Transliterator类 。 Euro sign is not in ISO-8859-1. (ISO-8859-15 was create ...
-
浏览器在UTF-8 cakePHP应用程序上检测到ISO-8859-1编码(Browser detects ISO-8859-1 encoding on UTF-8 cakePHP app)[2024-02-03]
我通过放入app / config / bootstrap.php文件的第一行解决了这个问题: header('Content-Type: text/html; charset=utf-8'); 简单甚至看起来很明显,但在这个托管中,cakePHP应用程序没有按预期工作。 响应标头始终回答Content-Type ISO-8859-1。 现在有了这个改变,它回答了UTF-8。 I solved the problem by putting in the first line of app/config/b ... -
它不适用于XML文件 : 目前,需要为处理源文件的每个插件单独配置源文件的字符编码。 在这种情况下,源文件指的是一些纯文本文件 - 与XML文件不同 - 缺乏指定所用文件编码的内在方法。 Java源文件是此类文本文件的最佳实例。 Velocity模板,BeanShell脚本和APT文档是更多示例。 此提议不适用于XML文件,因为它们的编码可以从文件本身确定 ,有关详细信息,请参阅XML编码。 It doesn't apply to XML files: Currently, the character en ...
-
好吧,我发现SET NAMES并不是那么好。 在文档中巅峰...... 我通常做的是执行4个查询: SET CHARACTER SET 'UTF8'; SET character_set_database = 'UTF8'; SET character_set_connection = 'UTF8'; SET character_set_server = 'UTF8'; 试一试,看看是否适合你...... 哦,记住,所有UTF-8字符<= 127也是有效的ISO-8859-1字符。 因此,如果流中只有<= ...
-
我通常一次检查一个可能的编码,就像这样 my $decoder = guess_encoding($data, 'utf8'); $decoder = guess_encoding($data, 'iso-8859-1') unless ref $decoder; die $decoder unless ref $decoder; printf "Decoding as %s\n\n", $decoder->name; $data = $decoder->decode($data); 如果可能的话,它选 ...
-
我会这样做: define('PILCROW', '¶'); // standard two-byte pilcrow character define('REPLACEMENT', $GLOBALS['linesep']); function fix_encoding($quote) { return mb_convert_encoding($quote, 'UTF-8', mb_detect_encoding($quote)); } function fix_line_breaks($quo ...
-
Laravel 4.2应用程序编码从UTF8到iso-8859-1(Laravel 4.2 application encoding from UTF8 to iso-8859-1)[2022-09-21]
为了解决这个问题,我做了以下工作: 更改了第106行中的表单助手/project/vendor/laravel/framework/src/llluminate/Html/FormBuilder.php 这个: $attributes['accept-charset'] = 'UTF-8'; 至: $attributes['accept-charset'] = 'latin1'; 这样,所有表单都是对数据库右符号的影响。 在此之后,由于我的应用程序不大,我创建了帮助程序,将给定的字符串从lati ...