当我用JDBC连接MySql数据库时,编译报了如下
错误:错误1:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
这要求我们注册驱动时,把Class.forName("com.mysql.jdbc.Driver")改成 Class.forName("com.mysql.cj.jdbc.Driver")当我信息满满的修改之后重新编译时,再次出现了错误:错误2:Fri Feb 22 08:55:38 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.这要求我们在设置url参数时,将useSSL=false,修改后 jdbc:mysql://localhost:3306/ds3?useSSL=false当我修改后,本以为这下应该没问题了,没想到,再一次出现了问题错误3:Exception in thread "main" java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.这要求我们修改时区,修改成jdbc:mysql://localhost:3306/ds3?useSSL=false&serverTimezone=UTC终于,不在报错误了。错误4:当我们配置xml
文件时,要把&转为其本身的转义字符配置properties文件的urlurl=jdbc:mysql:///ds3?useSSL=false&serverTimezone=UTC配置xml文件的url<property name="url">jdbc:mysql://localhost:3306/ds3?useSSL=false&serverTimezone=UTC</property>解决mysql自动断开连接的问题
有三个方法可以解决这个问题:
1:修改MySQL配置参数
2:修改JDBC
3:修改第三方的数据库连接池应用 Proxool.xml
方法1的解决方案:
这个参数的名称是 wait_timeout,其默认值为 28800秒(8小时)。其意义为关闭一个连接之前在这个连接上等到行动的秒数,也就是说,如果一个连接闲置超过这个选项所设置的秒数,MySQL 会主动断开这个连接。
看看这个是否对你有帮助
远程访问MySQL
帐号不允许从远程登陆,只要在localhost的那台电脑,登入mysql后,更改"mysql"数据库里的"user"表里的"host"项,从"localhost"改成"%"
解决方法:
1、改表法。【可以使用Navicat】
mysql
-uroot
-pvmwaremy
sql>use
mysql
mysql>updateuser
set
host
=
'%'
where
user
=
'root'
mysql>select
host,
user
fromuser
mysql>FLUSH
RIVILEGES
2、授权法。
你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT
ALLPRIVILEGES
ON
*.*
TO
'myuser'@'%'
IDENTIFIED
BY
'mypassword'
WITH
GRANT
OPTION
允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
GRANT
ALLPRIVILEGES
ON
*.*
TO
'myuser'@'192.168.1.3'
IDENTIFIED
BY
'mypassword'WITH
GRANT
OPTION
如果以上方法还不能使远程用户访问MySQL,
则需要修改windows
下的host
文件,增加远程用户IP地址
评论列表(0条)