[sr-dev] git:5.2:fc63e970: kamdbctl: split create user and grant access statements for mysql

Henning Westerholt hw at skalatan.de
Fri Jan 24 16:55:41 CET 2020


Module: kamailio
Branch: 5.2
Commit: fc63e970304ba74b7f6800176b0a9b41b7b39f52
URL: https://github.com/kamailio/kamailio/commit/fc63e970304ba74b7f6800176b0a9b41b7b39f52

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Henning Westerholt <hw at skalatan.de>
Date: 2020-01-24T16:54:44+01:00

kamdbctl: split create user and grant access statements for mysql

- MySQL 8 doesn't support all in one statement

(cherry picked from commit c0879add55bef77703f2259f224b4a1f954cd8bf)

---

Modified: utils/kamctl/kamdbctl.mysql

---

Diff:  https://github.com/kamailio/kamailio/commit/fc63e970304ba74b7f6800176b0a9b41b7b39f52.diff
Patch: https://github.com/kamailio/kamailio/commit/fc63e970304ba74b7f6800176b0a9b41b7b39f52.patch

---

diff --git a/utils/kamctl/kamdbctl.mysql b/utils/kamctl/kamdbctl.mysql
index 6103705bc0..e8f8d2e861 100644
--- a/utils/kamctl/kamdbctl.mysql
+++ b/utils/kamctl/kamdbctl.mysql
@@ -160,8 +160,10 @@ kamailio_db_grant () # pars: <database name>
 	minfo "granting privileges to database $1 ..."
 
 	# Users: kamailio is the regular user, kamailioro only for reading
-	sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '${DBRWUSER}'@'$DBHOST' IDENTIFIED BY '$DBRWPW';
-		GRANT SELECT ON $1.* TO '${DBROUSER}'@'$DBHOST' IDENTIFIED BY '$DBROPW';"
+	sql_query "" "CREATE USER '${DBRWUSER}'@'$DBHOST' IDENTIFIED BY '$DBRWPW';
+		GRANT ALL PRIVILEGES ON $1.* TO '${DBRWUSER}'@'$DBHOST';
+		CREATE USER '${DBROUSER}'@'$DBHOST' IDENTIFIED BY '$DBROPW';
+		GRANT SELECT ON $1.* TO '${DBROUSER}'@'$DBHOST';"
 
 	if [ $? -ne 0 ] ; then
 		merr "granting privileges to database $1 failed!"
@@ -169,8 +171,10 @@ kamailio_db_grant () # pars: <database name>
 	fi
 
 	if [ "$DBHOST" != "localhost" ] ; then
-		sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'localhost' IDENTIFIED  BY '$DBRWPW';
-			GRANT SELECT ON $1.* TO '$DBROUSER'@'localhost' IDENTIFIED BY '$DBROPW';"
+		sql_query "" "CREATE USER '$DBRWUSER'@'localhost' IDENTIFIED BY '$DBRWPW';
+			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'localhost';
+			CREATE USER '$DBROUSER'@'localhost' IDENTIFIED BY '$DBROPW';
+			GRANT SELECT ON $1.* TO '$DBROUSER'@'localhost';"
 		if [ $? -ne 0 ] ; then
 			merr "granting localhost privileges to database $1 failed!"
 			exit 1
@@ -178,8 +182,10 @@ kamailio_db_grant () # pars: <database name>
 	fi
 
 	if [ ! -z "$DBACCESSHOST" ] ; then
-		sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED  BY '$DBRWPW';
-			GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';"
+		sql_query "" "CREATE USER '$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBRWPW';
+			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST';
+			CREATE USER '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';
+			GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST';"
 		if [ $? -ne 0 ] ; then
 			merr "granting access host privileges to database $1 failed!"
 			exit 1




More information about the sr-dev mailing list