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;