Skip to content

Commit b895cf9

Browse files
committed
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 '';
1 parent 8173741 commit b895cf9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ private static void initDB(String dbPropsFile, String rootPassword, String[] dat
104104
List<String> queries = new ArrayList<String>();
105105
queries.add(String.format("drop database if exists `%s`", dbName));
106106
queries.add(String.format("create database `%s`", dbName));
107-
queries.add(String.format("GRANT ALL ON %s.* to '%s'@`localhost` identified by '%s'", dbName, username, password));
108-
queries.add(String.format("GRANT ALL ON %s.* to '%s'@`%%` identified by '%s'", dbName, username, password));
107+
queries.add(String.format("CREATE USER IF NOT EXISTS %s@`localhost` identified by '%s'", username, password));
108+
queries.add(String.format("CREATE USER IF NOT EXISTS %s@`%%` identified by '%s'", username, password));
109+
queries.add(String.format("GRANT ALL ON %s.* to '%s'@`localhost`", dbName, username));
110+
queries.add(String.format("GRANT ALL ON %s.* to '%s'@`%%`", dbName, username));
109111

110112
for (String query : queries) {
111113
runQuery(host, port, rootPassword, query, dryRun);

setup/db/create-database-simulator.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ DROP DATABASE IF EXISTS `simulator`;
2020

2121
CREATE DATABASE `simulator`;
2222

23-
GRANT ALL ON simulator.* to cloud@`localhost` identified by 'cloud';
24-
GRANT ALL ON simulator.* to cloud@`%` identified by 'cloud';
23+
GRANT ALL ON simulator.* to cloud@`localhost`;
24+
GRANT ALL ON simulator.* to cloud@`%`;
2525

2626
GRANT process ON *.* TO cloud@`localhost`;
2727
GRANT process ON *.* TO cloud@`%`;

setup/db/create-database.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ DROP DATABASE IF EXISTS `cloud`;
5555

5656
CREATE DATABASE `cloud`;
5757

58-
CREATE USER cloud identified by 'cloud';
58+
CREATE USER cloud@`localhost` identified by 'cloud';
59+
CREATE USER cloud@`%` identified by 'cloud';
5960

60-
GRANT ALL ON cloud.* to cloud@`localhost` identified by 'cloud';
61-
GRANT ALL ON cloud.* to cloud@`%` identified by 'cloud';
61+
GRANT ALL ON cloud.* to cloud@`localhost`;
62+
GRANT ALL ON cloud.* to cloud@`%`;
6263

6364
GRANT process ON *.* TO cloud@`localhost`;
6465
GRANT process ON *.* TO cloud@`%`;

0 commit comments

Comments
 (0)