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

Vue implements interface sliding effect

This article example shares the specific code of ...

Solve the problem of mysql's int primary key self-increment

Introduction When we use the MySQL database, we a...

Python 3.7 installation tutorial for MacBook

The detailed process of installing python3.7.0 on...

Best Practices Guide for MySQL Partitioned Tables

Preface: Partitioning is a table design pattern. ...

Hbase Getting Started

1. HBase Overview 1.1 What is HBase HBase is a No...

JavaScript implements front-end countdown effect

This article shares the specific code of JavaScri...

Detailed explanation of Vite's new experience

What is Vite? (It’s a new toy on the front end) V...

Vue implements the frame rate playback of the carousel

This article example shares the specific code of ...

Ubuntu 16.04 installation tutorial under VMware 12

This article shares with you the installation tut...

The use and difference between vue3 watch and watchEffect

1.watch listener Introducing watch import { ref, ...

Detailed analysis of MySQL master-slave delay phenomenon and principle

1. Phenomenon In the early morning, an index was ...