我在Ubuntu 15.10上使用本地MySQL数据库。
我有两个用户:root用户和名为java
且密码为password
的用户。后者用于Java JPA测试应用程序。
我需要'java'@'localhost'
拥有videogames
数据库的所有权限(我不关心安全性)。
我使用mysql -u root -p
进入控制台,然后执行GRANT ALL PRIVILEGES ON mydb.videogames TO 'java'@'localhost' WITH GRANT OPTION
。
然后我执行了mysql -u java -p
和show databases
,显示了用户java
可以访问的少数数据库,但它没有显示videogames
数据库。
使用Java / JPA应用程序连接会抛出异常Access denied for user 'java'@'localhost' to database 'videogames' (Error Code: 1044)
GRANT ALL PRIVILEGES ON mydb.videogames TO 'java'@'%' WITH GRANT OPTION
GRANT ALL PRIVILEGES ON mydb.* TO 'java'@'%' WITH GRANT OPTION
FLUSH PRIVILEGES
sudo service restart mysql
DROP USER ''
SHOW GRANTS
s的转储:
Grants for java@%
GRANT USAGE ON *.* TO 'java'@'%'
GRANT ALL PRIVILEGES ON 'mydb'.* TO 'java'@'%' WITH GRANT OPTION
GRANT ALL PRIVILEGES ON 'mydb'.'videogames' TO 'java'@'%' WITH GRANT OPTION
Grants for java@localhost
GRANT USAGE ON *.* TO 'java'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
GRANT ALL PRIVILEGES ON 'javabase'.* TO 'java'@'localhost'
GRANT ALL PRIVILEGES ON 'mydb'.* TO 'java'@'localhost' WITH GRANT OPTION
GRANT ALL PRIVILEGES ON 'mydb'.'videogames' TO 'java'@'localhost' WITH GRANT OPTION
转储SELECT user, host FROM mysql.user;
:
+------------------+--------------------------+
| user | host |
+------------------+--------------------------+
| java | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | (name of my pc) |
| debian-sys-maint | localhost |
| java | localhost |
| root | localhost |
+------------------+--------------------------+
感谢任何帮助。
答案 0 :(得分:3)
视频游戏是一个数据库,而不是一个表。
点之前的所有内容都是数据库,在表格之后。
所以这是对的:
GRANT ALL PRIVILEGES ON videogames.* TO 'java'@'localhost' WITH GRANT OPTION