Browse Source

Fix permission issue when using skip-name-resolve in conjunction with running a local MySQL database server and connecting via TCP. (#6611)

Laurents Meyer 4 years ago
parent
commit
822f510f4e
2 changed files with 17 additions and 11 deletions
  1. 11 2
      toolset/databases/mysql/create.sql
  2. 6 9
      toolset/databases/mysql/mysql.dockerfile

+ 11 - 2
toolset/databases/mysql/create.sql

@@ -2,6 +2,15 @@
 # http://stackoverflow.com/questions/37719818/the-server-time-zone-value-aest-is-unrecognized-or-represents-more-than-one-ti
 SET GLOBAL time_zone = '+00:00';
 
+CREATE USER 'benchmarkdbuser'@'%' IDENTIFIED WITH mysql_native_password BY 'benchmarkdbpass';
+CREATE USER 'benchmarkdbuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'benchmarkdbpass';
+
+-- GitHub Actions/CI run the database server on the same system as the benchmarks.
+-- Because we setup MySQL with the skip-name-resolve option, the IP address 127.0.0.1 might not be resolved to localhost
+-- anymore. This does not seem to matter, as long as Unix sockets are being used (e.g. when setting up the docker image),
+-- because the host is set to be localhost implicitly, but it matters for local TCP connections.
+CREATE USER 'benchmarkdbuser'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'benchmarkdbpass';
+
 # modified from SO answer http://stackoverflow.com/questions/5125096/for-loop-in-mysql
 CREATE DATABASE hello_world;
 USE hello_world;
@@ -12,10 +21,9 @@ CREATE TABLE  world (
   PRIMARY KEY  (id)
 )
 ENGINE=INNODB;
-CREATE USER 'benchmarkdbuser'@'%' IDENTIFIED WITH mysql_native_password BY 'benchmarkdbpass';
-CREATE USER 'benchmarkdbuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'benchmarkdbpass';
 GRANT ALL PRIVILEGES ON hello_world.world TO 'benchmarkdbuser'@'%';
 GRANT ALL PRIVILEGES ON hello_world.world TO 'benchmarkdbuser'@'localhost';
+GRANT ALL PRIVILEGES ON hello_world.world TO 'benchmarkdbuser'@'127.0.0.1';
 
 DELIMITER #
 CREATE PROCEDURE load_data()
@@ -46,6 +54,7 @@ CREATE TABLE  fortune (
 ENGINE=INNODB;
 GRANT ALL PRIVILEGES ON hello_world.fortune TO 'benchmarkdbuser'@'%';
 GRANT ALL PRIVILEGES ON hello_world.fortune TO 'benchmarkdbuser'@'localhost';
+GRANT ALL PRIVILEGES ON hello_world.fortune TO 'benchmarkdbuser'@'127.0.0.1';
 
 INSERT INTO fortune (message) VALUES ('fortune: No such file or directory');
 INSERT INTO fortune (message) VALUES ('A computer scientist is someone who fixes things that aren''t broken.');

+ 6 - 9
toolset/databases/mysql/mysql.dockerfile

@@ -32,15 +32,12 @@ RUN cp -R -p /var/lib/mysql /ssd/
 RUN cp -R -p /var/log/mysql /ssd/log
 RUN mkdir -p /var/run/mysqld
 
-# It may seem weird that we call `service mysql start` several times, but the RUN
-# directive is a 1-time operation for building this image. Subsequent RUN calls
-# do not see running processes from prior RUN calls; therefor, each command here
-# that relies on the mysql server running will explicitly start the server and
-# perform the work required.
 RUN chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd && \
-    mysqld & \
-    until mysql -uroot -psecret -e "exit"; do sleep 1; done && \
+    (mysqld &) && \
+    until mysqladmin -uroot -psecret ping; do sleep 1; done && \
     mysqladmin -uroot -psecret flush-hosts && \
-    mysql -uroot -psecret < create.sql
+    mysql -uroot -psecret < create.sql && \
+    mysqladmin -uroot -psecret shutdown && \
+    chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd
 
-CMD chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd && mysqld
+CMD ["mysqld"]