mysql开发中遇到的一些版本问题

时间:2022-03-27 03:54:05

以5和8做比较

	private static String dbType = "MySql";
	//private static String driver = "com.mysql.jdbc.Driver";   // 版本5
	private static String driver = "com.mysql.cj.jdbc.Driver";
	private static String url = "jdbc:mysql://localhost:3306/plusoft_test?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true"; //连接数据库(meizu是数据库名)
	private static String user = "root";
	private static String pwd = "root";

  

Unknown initial character set index ‘255‘ received from server. Initial client character set can be forced via the ‘characterEncoding‘ property.
 一般是字符集错误,MYSQL 5.5 之前, UTF8 编码只支持1-3个字节;从MYSQL5.5开始,可支持4个字节UTF编码utf8mb4;

需根据使用的mysql版本更换对应的连接包(mysql-connector-java-5.1.30-bin)。

 

建表语句也有些不同(8):

CREATE TABLE `t_educational` (
  `id` VARCHAR(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `name` VARCHAR(20) COLLATE utf8mb4_general_ci DEFAULT NULL

)ENGINE=InnoDB
CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci