Mysql:他乡遇故知

1、Java.sql.Timestamp 空串转义失败

Exception:java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

Remark:使用MySql 时, 数据库中的字段类型是timestamp的,默认为0000-00-00,但是在java项目编译的时候会被视为不合法的值,被JVM认为格式不正确

The Solution:在数据源Url中添加zeroDateTimeBehavior=convertToNull
这里写图片描述

2、Reset password 重置密码

Exception:ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password)

Remark:输入mysql密码,密码不正确,需要重置密码

The Solution

方法一:

# service mysqld stop    关闭mysql服务
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking

这里写图片描述

在另开一个终端
# mysql -u root mysql 
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# service mysqld restart 重启mysql服务
# mysql -u root -p 
Enter password: <输入新设的密码newpassword> 
mysql> 

方法二:

直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码: 
# mysql -udebian-sys-maint -p 
Enter password: <输入[client]节的密码> 
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# service mysqld restart 重启mysql服务
# mysql -u root -p 
Enter password: <输入新设的密码newpassword> 
mysql> 

3、Java connections database problem

Exception
Connections could not be acquired from the underlying database!
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not

Remark:数据库连接的一些问题

The Solution
1,驱动配置有误:driver=com.mysql.jdbc.Driver
2,数据库连接地址有误:url=jdbc:mysql://localhost:3306/test?3useUnicode=true&characterEncoding=utf8
3,密码或帐号有误:username=root password=root
4,数据库未启动或无权访问
5,项目未引入对应的驱动jar包mysql-connector-java-5.1.6-bin.jar
6,mysql root没有远程访问的权限,需要增加权限,增加权限的步骤如下:
进入mysql数据库:
grant all privileges on . to ‘root’@’%’ identified by ‘root’ with grant option;
flush privileges;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拾荒的小海螺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值