mysql-operator icon indicating copy to clipboard operation
mysql-operator copied to clipboard

Some users for operator are not passed into "init" container and will cause init not completed.

Open von1994 opened this issue 2 years ago • 1 comments

run initContainer "init"(clone-and-init) with bellow error: 2022-04-07T06:21:15.594988Z 1 [ERROR] 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@'%';' at line 1

operator-init.sql like this: SET @@SESSION.SQL_LOG_BIN = 0; SET GLOBAL READ_ONLY = 1; CREATE DATABASE IF NOT EXISTS sys_operator; DROP USER IF EXISTS @'%'; CREATE USER @'%' IDENTIFIED BY ''; GRANT SUPER, SHOW DATABASES, PROCESS, RELOAD, CREATE, SELECT ON *.* TO @'%'; GRANT REPLICATION SLAVE ON *.* TO @'%'; GRANT ALL ON sys_operator.* TO @'%'; DROP USER IF EXISTS @'%'; CREATE USER @'%' IDENTIFIED BY ''; GRANT SELECT, PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO @'%'; DROP USER IF EXISTS @'127.0.0.1'; CREATE USER @'127.0.0.1' IDENTIFIED BY ''; GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO @'127.0.0.1'; GRANT SELECT, CREATE ON sys_operator.heartbeat TO @'127.0.0.1'; ALTER USER @'127.0.0.1' WITH MAX_USER_CONNECTIONS 3; DROP USER IF EXISTS sys_heartbeat@'127.0.0.1'; CREATE USER sys_heartbeat@'127.0.0.1' IDENTIFIED BY 'nOlYerUg82'; GRANT CREATE, SELECT, DELETE, UPDATE, INSERT ON sys_operator.heartbeat TO sys_heartbeat@'127.0.0.1'; GRANT REPLICATION CLIENT ON *.* TO sys_heartbeat@'127.0.0.1'; DROP TABLE IF EXISTS sys_operator.status; CREATE TABLE IF NOT EXISTS sys_operator.status ( name varchar(64) PRIMARY KEY, value varchar(8192) NOT NULL );

The sql contains "create user" is incomplete. The info in secret generated by operator are not passed into environments and caused sql syntax is invalid.

Maybe should inject envs like bellow: image

von1994 avatar Apr 07 '22 07:04 von1994

Is there any reproduce steps?

In my opinion, the related user and password have passed to init container actually.

Here is code: https://github.com/bitpoke/mysql-operator/blob/b7ea748da61515346b69d7d8314be8e672b5c915/pkg/controller/mysqlcluster/internal/syncer/statefullset.go#L618-L626

From above, the init and sidecar container will be populated all related envs from cluster secret and the SQL will be complete.

drivebyer avatar Aug 30 '22 12:08 drivebyer