java.sql.SQLException:用户 'userapp'@'localhost' / glassfish 的访问被拒绝
java.sql.SQLException: Access denied for user 'userapp'@'localhost' / glassfish
我正在尝试使用 javax.sql.DataSource 注入 servlet (glassfish)
@Resource (name="jdbc/MysqlDS" )
javax.sql.DataSource mysqlDS;
以下语句失败,抛出"java.sql.SQLException: Access denied for user 'userapp'@'localhost' (using password: YES)":
con=mysqlDS.getConnection();
PreparedStatement pstmt=con.prepareStatement("select now()");
或
con=mysqlDS.getConnection("userapp","userpassword");
PreparedStatement pstmt=con.prepareStatement("select now()");
但以下是成功的:
Class.forName("com.mysql.jdbc.Driver");
con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/user_lindenb", "appuser", "userpassword");
w.println("OK");
con.close(); con=null;
或
con=mysqlDS.getConnection("root","root_password");
或
con=mysqlDS.getConnection("me","mypassword");
或
$ mysql -u appuser --password=userpassword -D user_lindenb -e 'select now()'
+---------------------+
| now() |
+---------------------+
| 2015-08-05 10:19:07 |
+---------------------+
资助声明如下:
grant insert,select,update,delete on user_lindenb.* TO 'appuser'@'localhost' identified by 'userpassword';
资源声明如下
asadmin --port 8138 create-jdbc-connection-pool \
--datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource \
--restype javax.sql.DataSource \
--property "password=userpassword:user=userapp:serverName=localhost:databaseName=user_lindenb" \
MysqlDS
asadmin --port 8138 create-jdbc-resource \
--connectionpoolid MysqlDS \
"jdbc/MysqlDS"
这个用户有什么问题 'userapp' ?
谢谢。
在我添加
之后
grant USAGE on *.* TO 'appuser'@'localhost' identified by 'adminadmin';
一切正常...我不明白为什么。
我正在尝试使用 javax.sql.DataSource 注入 servlet (glassfish)
@Resource (name="jdbc/MysqlDS" )
javax.sql.DataSource mysqlDS;
以下语句失败,抛出"java.sql.SQLException: Access denied for user 'userapp'@'localhost' (using password: YES)":
con=mysqlDS.getConnection();
PreparedStatement pstmt=con.prepareStatement("select now()");
或
con=mysqlDS.getConnection("userapp","userpassword");
PreparedStatement pstmt=con.prepareStatement("select now()");
但以下是成功的:
Class.forName("com.mysql.jdbc.Driver");
con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/user_lindenb", "appuser", "userpassword");
w.println("OK");
con.close(); con=null;
或
con=mysqlDS.getConnection("root","root_password");
或
con=mysqlDS.getConnection("me","mypassword");
或
$ mysql -u appuser --password=userpassword -D user_lindenb -e 'select now()'
+---------------------+
| now() |
+---------------------+
| 2015-08-05 10:19:07 |
+---------------------+
资助声明如下:
grant insert,select,update,delete on user_lindenb.* TO 'appuser'@'localhost' identified by 'userpassword';
资源声明如下
asadmin --port 8138 create-jdbc-connection-pool \
--datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource \
--restype javax.sql.DataSource \
--property "password=userpassword:user=userapp:serverName=localhost:databaseName=user_lindenb" \
MysqlDS
asadmin --port 8138 create-jdbc-resource \
--connectionpoolid MysqlDS \
"jdbc/MysqlDS"
这个用户有什么问题 'userapp' ?
谢谢。
在我添加
之后grant USAGE on *.* TO 'appuser'@'localhost' identified by 'adminadmin';
一切正常...我不明白为什么。