• 启动容器

    首先确保 mysql 容器已经启动,详见 开发环境搭建

    介绍

    本小节介绍了如何初始化Choerodon 的数据库。

    创建Mysql数据库

    1.查看容器,确认存在容器名为mysql的容器。

    2.用choerodon用户命令行登陆 mysql 容器,密码为 123456

    $ docker exec -ti mysql mysql -u choerodon -p
    

    3.创建用户和数据库。

    CREATE USER 'choerodon'@'%' IDENTIFIED BY "123456";
    CREATE DATABASE IF NOT EXISTS iam_service DEFAULT CHARACTER SET utf8;
    CREATE DATABASE IF NOT EXISTS manager_service DEFAULT CHARACTER SET utf8;
    CREATE DATABASE IF NOT EXISTS asgard_service DEFAULT CHARACTER SET utf8;
    CREATE DATABASE IF NOT EXISTS notify_service DEFAULT CHARACTER SET utf8;
    GRANT ALL PRIVILEGES ON iam_service.* TO choerodon@'%';\
    GRANT ALL PRIVILEGES ON manager_service.* TO choerodon@'%';\
    GRANT ALL PRIVILEGES ON asgard_service.* TO choerodon@'%';\
    GRANT ALL PRIVILEGES ON notify_service.* TO choerodon@'%';\
    FLUSH PRIVILEGES;
    

    4.查看用户与数据库。

    $ mysql> select User from mysql.user;
    +-----------+
    | User      |
    +-----------+
    | choerodon |
    | root      |
    | mysql.sys |
    +-----------+
    3 rows in set (0.00 sec)
    
    mysql> show databases;
    +-----------------------------+
    | Database                    |
    +-----------------------------+
    | asgard_service              |
    | information_schema          |
    | iam_service                 |
    | manager_service             |
    | notify_service              |
    | todo_service                |
    | mysql                       |
    | performance_schema          |
    | sys                         |
    +-----------------------------+
    9 rows in set (0.01 sec)
    
    

    初始化数据库

    需初始化manager-serviceiam-service两个数据库。

    1.新建初始化数据库临时目录,并创建初始化脚本。

    $ mkdir -p tmp
    $ cd tmp
    $ touch init-local-database.sh
    

    2.修改初始化脚本。

    #!/bin/bash
    # get manager-service
    git clone https://github.com/choerodon/manager-service.git manager-service
    mkdir -p manager/script
    cp -r ./manager-service/src/main/resources/script/db ./manager/script
    rm -rf ./manager-service
    
    # get user-service
    git clone https://github.com/choerodon/iam-service.git iam-service
    mkdir -p iam/script
    cp -r ./iam-service/src/main/resources/script/db ./iam/script
    rm -rf ./iam-service
    
    # init manager-service
    java -Dspring.datasource.url="jdbc:mysql://localhost:3306/manager_service?useUnicode=true&characterEncoding=utf-8&useSSL=false" \
     -Dspring.datasource.username=choerodon \
     -Dspring.datasource.password=123456 \
     -Ddata.drop=false -Ddata.init=init \
     -Ddata.dir=./manager \
     -jar ../bin/choerodon-tool-liquibase.jar
    
    # init iam-service
    java -Dspring.datasource.url="jdbc:mysql://localhost:3306/iam_service?useUnicode=true&characterEncoding=utf-8&useSSL=false" \
     -Dspring.datasource.username=choerodon \
     -Dspring.datasource.password=123456 \
     -Ddata.drop=false -Ddata.init=init \
     -Ddata.dir=./iam \
     -jar ../bin/choerodon-tool-liquibase.jar
    

    3.运行脚本。

    $ sh ./init-local-database.sh
    

    4.命令执行成功之后,刷新数据库,会出现初始化脚本中的表以及初始化数据。

    本地需要的manager-serviceiam-service 尽量以最新版本的tag 为主。如果初始化数据库失败,可以下载最新版本的choerodon-tool-liquibase.jar 并重命名覆盖./bin/choerodon-tool-liquibase.jar,然后重新执行init-local-database.sh 脚本