From 418c66b32f6a161671ceb6978d665fcb4627d7b7 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 30 Apr 2020 03:17:29 +0530 Subject: [PATCH 1/3] db: add support for MySQL 8 - Splits commands to create user and grant access on database, the old statement is no longer supported by MySQL 8.x - `NO_AUTO_CREATE_USER` is no longer supported by MySQL 8.x so remove that from db.properties conn parameters For mysql-server 8.x setup the following changes were added/tested to make it work with CloudStack in /etc/mysql/mysql.conf.d/mysqld.cnf and then restart the mysql-server process: server_id = 1 sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION" innodb_rollback_on_timeout=1 innodb_lock_wait_timeout=600 max_connections=1000 log-bin=mysql-bin binlog-format = 'ROW' default-authentication-plugin=mysql_native_password Notice the last line above, this is to reset the old password based authentication used by MySQL 5.x. Developers can set empty password as follows: > sudo mysql -u root ALTER USER 'root'@'localhost' IDENTIFIED BY ''; Signed-off-by: Rohit Yadav --- .../src/main/java/com/cloud/upgrade/DatabaseCreator.java | 6 ++++-- setup/db/create-database-simulator.sql | 4 ++-- setup/db/create-database.sql | 7 ++++--- utils/conf/db.properties | 3 +-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java index 2281e1d2399e..7bf5cf627902 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java @@ -104,8 +104,10 @@ private static void initDB(String dbPropsFile, String rootPassword, String[] dat List queries = new ArrayList(); queries.add(String.format("drop database if exists `%s`", dbName)); queries.add(String.format("create database `%s`", dbName)); - queries.add(String.format("GRANT ALL ON %s.* to '%s'@`localhost` identified by '%s'", dbName, username, password)); - queries.add(String.format("GRANT ALL ON %s.* to '%s'@`%%` identified by '%s'", dbName, username, password)); + queries.add(String.format("CREATE USER IF NOT EXISTS %s@`localhost` identified by '%s'", username, password)); + queries.add(String.format("CREATE USER IF NOT EXISTS %s@`%%` identified by '%s'", username, password)); + queries.add(String.format("GRANT ALL ON %s.* to '%s'@`localhost`", dbName, username)); + queries.add(String.format("GRANT ALL ON %s.* to '%s'@`%%`", dbName, username)); for (String query : queries) { runQuery(host, port, rootPassword, query, dryRun); diff --git a/setup/db/create-database-simulator.sql b/setup/db/create-database-simulator.sql index 8924eda3ff5a..b61ce1b8d406 100644 --- a/setup/db/create-database-simulator.sql +++ b/setup/db/create-database-simulator.sql @@ -20,8 +20,8 @@ DROP DATABASE IF EXISTS `simulator`; CREATE DATABASE `simulator`; -GRANT ALL ON simulator.* to cloud@`localhost` identified by 'cloud'; -GRANT ALL ON simulator.* to cloud@`%` identified by 'cloud'; +GRANT ALL ON simulator.* to cloud@`localhost`; +GRANT ALL ON simulator.* to cloud@`%`; GRANT process ON *.* TO cloud@`localhost`; GRANT process ON *.* TO cloud@`%`; diff --git a/setup/db/create-database.sql b/setup/db/create-database.sql index 51f56565bf41..81e13f9fe229 100644 --- a/setup/db/create-database.sql +++ b/setup/db/create-database.sql @@ -55,10 +55,11 @@ DROP DATABASE IF EXISTS `cloud`; CREATE DATABASE `cloud`; -CREATE USER cloud identified by 'cloud'; +CREATE USER cloud@`localhost` identified by 'cloud'; +CREATE USER cloud@`%` identified by 'cloud'; -GRANT ALL ON cloud.* to cloud@`localhost` identified by 'cloud'; -GRANT ALL ON cloud.* to cloud@`%` identified by 'cloud'; +GRANT ALL ON cloud.* to cloud@`localhost`; +GRANT ALL ON cloud.* to cloud@`%`; GRANT process ON *.* TO cloud@`localhost`; GRANT process ON *.* TO cloud@`%`; diff --git a/utils/conf/db.properties b/utils/conf/db.properties index 2fd6910368a6..5b1bae423a42 100644 --- a/utils/conf/db.properties +++ b/utils/conf/db.properties @@ -44,8 +44,7 @@ db.cloud.testWhileIdle=true db.cloud.timeBetweenEvictionRunsMillis=40000 db.cloud.minEvictableIdleTimeMillis=240000 db.cloud.poolPreparedStatements=false -db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&prepStmtCacheSqlLimit=4096&sessionVariables=sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' - +db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&prepStmtCacheSqlLimit=4096&sessionVariables=sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION' # usage database settings db.usage.username=cloud db.usage.password=cloud From 94e7cc743778250905365ff36a9d6aa7184822b3 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 30 Apr 2020 03:31:44 +0530 Subject: [PATCH 2/3] fix sql_mode in default db.properties Signed-off-by: Rohit Yadav --- client/conf/db.properties.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/conf/db.properties.in b/client/conf/db.properties.in index 2f1dcf0d6b84..b0d07573dbf8 100644 --- a/client/conf/db.properties.in +++ b/client/conf/db.properties.in @@ -39,7 +39,7 @@ db.cloud.testWhileIdle=true db.cloud.timeBetweenEvictionRunsMillis=40000 db.cloud.minEvictableIdleTimeMillis=240000 db.cloud.poolPreparedStatements=false -db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&sessionVariables=sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' +db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&sessionVariables=sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' # CloudStack database SSL settings db.cloud.useSSL=false From b72ec351bb3795e7271441c5417354ce6d0dd30e Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 30 Apr 2020 15:29:01 +0530 Subject: [PATCH 3/3] fix dupe Signed-off-by: Rohit Yadav --- utils/conf/db.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/conf/db.properties b/utils/conf/db.properties index 5b1bae423a42..83051dbfca9d 100644 --- a/utils/conf/db.properties +++ b/utils/conf/db.properties @@ -44,7 +44,8 @@ db.cloud.testWhileIdle=true db.cloud.timeBetweenEvictionRunsMillis=40000 db.cloud.minEvictableIdleTimeMillis=240000 db.cloud.poolPreparedStatements=false -db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&prepStmtCacheSqlLimit=4096&sessionVariables=sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION' +db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&prepStmtCacheSqlLimit=4096&sessionVariables=sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' + # usage database settings db.usage.username=cloud db.usage.password=cloud