云化的Mysql如何初始化用户数据

分析用户如果需要在一个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: 我爱小砚 乀(ˉεˉ乀)
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!