Skip to content

Commit

Permalink
[AMORO-1899] improve init schema in mysql (#1938)
Browse files Browse the repository at this point in the history
* [AMORO-1899] improve init schema in mysql

* [AMORO-1899] improve doc
  • Loading branch information
Kyofin authored Sep 8, 2023
1 parent 3e9f709 commit b4c01ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,16 @@ private void createTablesIfNeed(Configurations config) {
query = "SELECT 1 FROM SYS.SYSTABLES WHERE TABLENAME = 'CATALOG_METADATA'";
} else if (ArcticManagementConf.DB_TYPE_MYSQL.equals(dbTypeConfig)) {
query = String.format(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '%s' AND table_name = '%s'",
"SELECT 1 FROM information_schema.tables WHERE table_schema = '%s' AND table_name = '%s'",
connection.getCatalog(), "CATALOG_METADATA");
}
ResultSet rs = statement.executeQuery(query);
if (!rs.next()) {
ScriptRunner runner = new ScriptRunner(connection);
runner.runScript(new InputStreamReader(Files.newInputStream(
Paths.get(getInitSqlScriptPath(dbTypeConfig))),
StandardCharsets.UTF_8));
try (ResultSet rs = statement.executeQuery(query);) {
if (!rs.next()) {
ScriptRunner runner = new ScriptRunner(connection);
runner.runScript(new InputStreamReader(Files.newInputStream(
Paths.get(getInitSqlScriptPath(dbTypeConfig))),
StandardCharsets.UTF_8));
}
}
} catch (Exception e) {
throw new IllegalStateException("Create tables failed", e);
Expand Down
28 changes: 3 additions & 25 deletions docs/admin-guides/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,11 @@ make sure the port is not used before configuring it
### Configure system database
Users can use MySQL as the system database instead of Derby. To do so, the system database must first be initialized in MySQL:
Users can use MySQL as the system database instead of Derby.
```shell
$ mysql -h{mysql-host-IP} -P{mysql-port} -u{username} -p
Enter password:
'Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41592724
Server version: 5.7.20-v3-log Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> create database amoro;
Query OK, 1 row affected (0.01 sec)

mysql> use amoro;
Database changed
mysql> source {ARCTIC_HOME}/conf/mysql/ams-mysql-init.sql
```
Create an empty database in MySQL, then AMS will automatically create table structures in this MySQL database when it first started.
Add MySQL configuration under `ams`:
One thing you need to do is Adding MySQL configuration under `config.yaml` of Ams:

```yaml
ams:
Expand Down

0 comments on commit b4c01ef

Please sign in to comment.