A brief analysis of the problem of Mysql 8.0 version driving getTables to return all database tables

A brief analysis of the problem of Mysql 8.0 version driving getTables to return all database tables

Preface

This article mainly introduces the relevant content about the Mysql8.0 driver getTables returning all the tables in the library. The MySQL Connector/J 8.0 version driver is backward compatible with the previous 5.5+ version of MySQL. If you are using 5.5+ version of MySQL, you can upgrade to the 8.0 version driver.

If you are using the 5.X version of the driver, you need to change the Driver Class to: com.mysql.cj.jdbc.Driver

It should be noted that:

The parameters related to the driver DataSource in version 8.0 have changed:

For example, the 8.0 version driver changes the default value of the parameter nullCatalogMeansCurrent from true to false. If you use DatabaseMetaData.getTables to get all table information, the 8.0 version driver will return all database tables.

// By default, all database tables are returned, not just the database specified by datasource databaseMetaData.getTables(null, null, null, new String[]{"TABLE"})

The solution is to change this parameter to true when the connection pool is initialized. Take HikariCP as an example:

Java Config:

HikariConfig config = new HikariConfig();
...
config.addDataSourceProperty("nullCatalogMeansCurrent", true);

Spring Boot Configuration:

spring.datasource.hikari.data-source-properties.nullCatalogMeansCurrent=true

For other parameter changes, please refer to [official documentation]

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Brief analysis of the various versions of mysql.data.dll driver
  • Detailed explanation of the problems encountered when using the Mysql8.0 version driver in Mybatis reverse engineering

<<:  Detailed explanation of samba + OPENldap to build a file sharing server

>>:  Vue.set() and this.$set() usage and difference

Recommend

Detailed explanation of this pointing in JS arrow function

Arrow function is a new feature in ES6. It does n...

Summary of common problems and solutions in Vue (recommended)

There are some issues that are not limited to Vue...

Implementation example of nginx access control

About Nginx, a high-performance, lightweight web ...

How to upload the jar package to nexus via the web page

When using Maven to manage projects, how to uploa...

VUE+Canvas realizes the whole process of a simple Gobang game

Preface In terms of layout, Gobang is much simple...

mysql calculation function details

Table of contents 2. Field concatenation 2. Give ...

Example code for implementing background blur effect with CSS

Is it the effect below? If so, please continue re...

Example of adding multi-language function to Vue background management

Table of contents 1. First, configure the main.js...

Simple web page code used in NetEase blog

How to use the code in NetEase Blog: First log in...

Summary of various methods for JavaScript to determine whether it is an array

Table of contents Preface Array.isArray construct...

Detailed explanation on how to modify the default port of nginx

First find out where the configuration file is wh...