Nacos can be used not only as a registry, but also as a configuration center. Nacos configurations are stored in memory by default, and for some projects there are often hundreds or thousands of configuration items that are very important. In this scenario we can save the configuration to MySQL. To persist our configuration and ensure that it will not be lost if Nacos is restarted or the service node fails.

Environment: NACOS-server-1.4.2

Perform initialization data

Nacos-server provides the nacos-mysql. SQL script in the conf directory to initialize the nacOS-configured table structure.

Modifying link Information

Nacos is also a spring-boot application. So we can configure MySQL link information by modifying the application.properties file.

### If use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=JDBC: mysql: / / 127.0.0.1:3306 / nacos_config? characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTime zone=UTC
db.user.0=nacos
db.password.0=nacos
Copy the code

Note that the default account, password, and database are configured with NACOS. You need to configure them according to the actual situation

Restart the service

Once the configuration is complete, we need to restart the Nacos service.

MySQL > query MySQL

Add the configuration

First we need to add configuration information and publish it, at which point Nacos is automatically stored in the MySQL database. Here’s how I added the configuration.

MySQL > select * from ‘MySQL’;

Once the configuration is added, we can look at the Nacos table to query the data we just added.

reference

www.cnblogs.com/exce-ben/ar…