Linux非root用户C3P0连接MySQL权限问题

今天想把之前在windows下开发的web项目移到linux下来开发,用的框架是spingmvc+spring+hibernate。myeclipse部署项目到tomcat,却抛出异常,控制台信息:java.sql.SQLException: Access denied for user ‘canva’@’localhost’ (using password: YES)
刚开始我还觉得奇怪,db.properties配置的user明明是root,为什么现在是以Debian系统的当前用户去登录呢?于是我切换成root用户重新登录系统,发现一切正常,连接为’root’@’localhost’。于是发现了问题所在,接下来就来解决这个问题。
打开命令行界面:

sudo mysql_setpermission

输入数据库root用户密码,之后有如下选项:
1. Set password for an existing user.
2. Create a database + user privilege for that database
and host combination (user can only do SELECT)
3. Create/append user privilege for an existing database
and host combination (user can only do SELECT)
4. Create/append broader user privileges for an existing
database and host combination
(user can do SELECT,INSERT,UPDATE,DELETE)
5. Create/append quite extended user privileges for an
existing database and host combination (user can do
SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,
LOCK TABLES,CREATE TEMPORARY TABLES)
6. Create/append full privileges for an existing database
and host combination (user has FULL privilege)
7. Remove all privileges for for an existing database and
host combination.
(user will have all permission fields set to N)
0. exit this program
这里我选择4来新建一个名字和我当前系统用户一样且只有增删改查权限的数据库用户,如果要得到所有权限请选择6。接下来只要按提示操作就行了,选择一个或多个数据库,填写用户名、密码,设置连接方式(localhost)。
这样就创建了一个和自己系统用户对应的数据库用户,接下来更改db.properties,把user和password设置成刚才新建的用户。举例如下:

jdbcUrl=jdbc\:mysql\://localhost\:3306/countryside?useUnicode\=true&characterEncoding\=utf8
driverClass=com.mysql.jdbc.Driver
user=canva
password=123456
initialPoolSize=10
maxPoolSize=30

接下来就能连接上!

猜你喜欢

转载自blog.csdn.net/CanvaChen/article/details/52734543
今日推荐