雲化的Mysql如何初始化使用者資料

Yark發表於2021-08-02

分析使用者如果需要在一個mysql中初始化自己想要的資料有如下辦法:

  • 使用者有一個mysql客戶端(圖形化navicat 或 命令列的mysql終端),在雲上的做法一般是有一個webshell命令終端;
  • 使用者需要在自己的應用程式中有初始化資料部分,此部分程式用於檢測所連線的資料庫中是否有需要的資料資訊,若沒有則自動執行程式中所設定好的初始化指令碼; (如: Davinci 啟動時檢測到所連的mysq伺服器沒有資料則自動執行專案的bin目錄下的 initdb.sh來進行sql匯入)

dockerhub上mysql 映象中關於的資料庫例項初始化的描述,如下:

Initializing a fresh instance

When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.

:point_right::

  • 當首次啟動資料庫服務時,將會自動執行 /docker-entrypoint-initdb.d目錄下的.sh、.sql、.sql.gz(按照字母順序)初始化檔案到MYSQL_DATABASE變數指定的資料庫中
  • 在雲的環境下,我們可以在mysql應用初始化前掛載上初始化sql檔案,並使用MYSQL_DATABASE變數指定所需的資料庫名稱
本作品採用《CC 協議》,轉載必須註明作者和本文連結
:kissing_closed_eyes: 我愛小硯 乀(ˉεˉ乀)

相關文章