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

Nginx's practical method for solving cross-domain problems

Separate the front and back ends and use nginx to...

How to uninstall MySQL 5.7.19 under Linux

1. Find out whether MySQL was installed before Co...

How to completely delete and uninstall MySQL in Windows 10

Preface This article introduces a tutorial on how...

Docker Compose installation and usage steps

Table of contents 1. What is Docker Compose? 2. D...

Five ways to traverse JavaScript arrays

Table of contents 1. for loop: basic and simple 2...

Detailed explanation of rpm installation in mysql

View installation and uninstallation # View rpm -...

Web page HTML code explanation: ordered list and unordered list

In this section, we will learn about list element...

Summary of Mysql common benchmark commands

mysqlslap Common parameter description –auto-gene...

CSS3 uses scale() and rotate() to achieve zooming and rotation

1. scale() method Zoom refers to "reducing&q...

Detailed example of how to implement transaction commit and rollback in mysql

Recently, we need to perform a scheduled migratio...

The most basic code for web pages

◆Add to favorites illustrate Click to add your we...