Created
September 22, 2020 20:57
-
-
Save guss77/6747e48dd401d1ad36e5b4092ccfcfdd to your computer and use it in GitHub Desktop.
MariaDB update table with UUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
database: | |
image: mariadb:latest | |
environment: | |
MYSQL_ROOT_PASSWORD: secret | |
MYSQL_DATABASE: demouuid | |
MYSQL_USER: demouuid | |
MYSQL_PASSWORD: demouuid | |
volumes: | |
- ./test.sql:/docker-entrypoint-initdb.d/test.sql | |
- data-volume:/var/lib/mysql | |
volumes: | |
data-volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COMPOSE := docker-compose -p demouuid | |
start: | |
$(COMPOSE) up -d | |
sleep 3 | |
while $(COMPOSE) ps | grep -q database; do \ | |
$(COMPOSE) logs 2>/dev/null| grep -q 'MySQL init process done.' && break;\ | |
$(COMPOSE) logs 2>/dev/null| grep -i error && break;\ | |
$(COMPOSE) ps | grep -q Exit && break;\ | |
done | |
sleep 3 | |
$(MAKE) output clean | |
clean: | |
$(COMPOSE) down || true | |
docker volume rm demouuid_data-volume || true | |
output: | |
$(eval DBIP := $(shell docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' demouuid_database_1)) | |
$(COMPOSE) run --rm database mysql -h${DBIP} -udemouuid -pdemouuid demouuid -e 'select * from foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE foo (`id` int primary key not null auto_increment, `name` varchar(10), `uuid` binary(36)); | |
INSERT INTO foo (name) VALUES ('Ar1mie8m'); | |
INSERT INTO foo (name) VALUES ('Ne1Thohb'); | |
INSERT INTO foo (name) VALUES ('aec6IeR2'); | |
INSERT INTO foo (name) VALUES ('Pahbie0S'); | |
INSERT INTO foo (name) VALUES ('AhSooy1b'); | |
INSERT INTO foo (name) VALUES ('Iechi1ee'); | |
INSERT INTO foo (name) VALUES ('eiSekah9'); | |
INSERT INTO foo (name) VALUES ('eePhie4f'); | |
INSERT INTO foo (name) VALUES ('poiBoo1A'); | |
INSERT INTO foo (name) VALUES ('geeJ9Eik'); | |
INSERT INTO foo (name) VALUES ('up9Eet3I'); | |
INSERT INTO foo (name) VALUES ('Sai7Niej'); | |
INSERT INTO foo (name) VALUES ('aexosa9O'); | |
INSERT INTO foo (name) VALUES ('Ohkeeco5'); | |
INSERT INTO foo (name) VALUES ('biaPahN7'); | |
INSERT INTO foo (name) VALUES ('ir8eNee0'); | |
INSERT INTO foo (name) VALUES ('eePae9ho'); | |
INSERT INTO foo (name) VALUES ('Nejoh6te'); | |
INSERT INTO foo (name) VALUES ('gavoNei5'); | |
INSERT INTO foo (name) VALUES ('ahqu3Kah'); | |
INSERT INTO foo (name) VALUES ('zai7foX8'); | |
INSERT INTO foo (name) VALUES ('Ti1Koobo'); | |
INSERT INTO foo (name) VALUES ('EupahP6e'); | |
INSERT INTO foo (name) VALUES ('Du6aicoh'); | |
INSERT INTO foo (name) VALUES ('Ahqu0Gii'); | |
INSERT INTO foo (name) VALUES ('iPh2oegh'); | |
INSERT INTO foo (name) VALUES ('oTee9zee'); | |
INSERT INTO foo (name) VALUES ('iebeid6P'); | |
INSERT INTO foo (name) VALUES ('aeTunia4'); | |
INSERT INTO foo (name) VALUES ('ou9Picae'); | |
INSERT INTO foo (name) VALUES ('Etadov2v'); | |
INSERT INTO foo (name) VALUES ('xohFeez2'); | |
INSERT INTO foo (name) VALUES ('zei2Phe8'); | |
INSERT INTO foo (name) VALUES ('Ieb5biev'); | |
INSERT INTO foo (name) VALUES ('Roo0phie'); | |
INSERT INTO foo (name) VALUES ('jeB6CaC3'); | |
INSERT INTO foo (name) VALUES ('Aeph5vo2'); | |
INSERT INTO foo (name) VALUES ('ki5Keide'); | |
INSERT INTO foo (name) VALUES ('eThaeYe5'); | |
INSERT INTO foo (name) VALUES ('shae7Ahf'); | |
INSERT INTO foo (name) VALUES ('Fie4ieru'); | |
INSERT INTO foo (name) VALUES ('Gahlai7p'); | |
INSERT INTO foo (name) VALUES ('ieMe2ohr'); | |
INSERT INTO foo (name) VALUES ('IPaix7Ii'); | |
INSERT INTO foo (name) VALUES ('uH7cot0o'); | |
INSERT INTO foo (name) VALUES ('Oubee2ie'); | |
INSERT INTO foo (name) VALUES ('Aeche7Ee'); | |
INSERT INTO foo (name) VALUES ('Ehi4jaej'); | |
INSERT INTO foo (name) VALUES ('Maipie0W'); | |
INSERT INTO foo (name) VALUES ('ue0shieS'); | |
INSERT INTO foo (name) VALUES ('eNgu0rai'); | |
INSERT INTO foo (name) VALUES ('Im3yaola'); | |
INSERT INTO foo (name) VALUES ('lie8waeW'); | |
INSERT INTO foo (name) VALUES ('iuc9cueP'); | |
INSERT INTO foo (name) VALUES ('Die2sah6'); | |
INSERT INTO foo (name) VALUES ('Soo2Aesu'); | |
INSERT INTO foo (name) VALUES ('AX2hoop2'); | |
INSERT INTO foo (name) VALUES ('Xi9EoJ5i'); | |
INSERT INTO foo (name) VALUES ('ohC6sooc'); | |
INSERT INTO foo (name) VALUES ('ohTh7eep'); | |
INSERT INTO foo (name) VALUES ('ahPah4ej'); | |
INSERT INTO foo (name) VALUES ('wohph4Oh'); | |
INSERT INTO foo (name) VALUES ('Pei2aebi'); | |
INSERT INTO foo (name) VALUES ('Kahpoo9o'); | |
INSERT INTO foo (name) VALUES ('aej8na5O'); | |
INSERT INTO foo (name) VALUES ('eup5Achi'); | |
INSERT INTO foo (name) VALUES ('cahgh4Ne'); | |
INSERT INTO foo (name) VALUES ('xiot8ohG'); | |
INSERT INTO foo (name) VALUES ('Uo2Utoo1'); | |
INSERT INTO foo (name) VALUES ('Ael4shoo'); | |
INSERT INTO foo (name) VALUES ('Udai5eiR'); | |
INSERT INTO foo (name) VALUES ('IraH5iey'); | |
INSERT INTO foo (name) VALUES ('yae9aiNo'); | |
INSERT INTO foo (name) VALUES ('cooh1Shu'); | |
INSERT INTO foo (name) VALUES ('Ae3hieTh'); | |
INSERT INTO foo (name) VALUES ('Nud8ooBi'); | |
INSERT INTO foo (name) VALUES ('AuY6Feet'); | |
INSERT INTO foo (name) VALUES ('eePhee0r'); | |
INSERT INTO foo (name) VALUES ('Ruihaev0'); | |
INSERT INTO foo (name) VALUES ('chohBeu6'); | |
INSERT INTO foo (name) VALUES ('ooFaad9E'); | |
INSERT INTO foo (name) VALUES ('ohx7ueM6'); | |
INSERT INTO foo (name) VALUES ('ouZ7aiqu'); | |
INSERT INTO foo (name) VALUES ('feche1Ev'); | |
INSERT INTO foo (name) VALUES ('ea4Iefai'); | |
INSERT INTO foo (name) VALUES ('IuD7bo5b'); | |
INSERT INTO foo (name) VALUES ('cei3Ahki'); | |
INSERT INTO foo (name) VALUES ('Quuk3zoh'); | |
INSERT INTO foo (name) VALUES ('ait8Roo3'); | |
INSERT INTO foo (name) VALUES ('iosh3Aej'); | |
INSERT INTO foo (name) VALUES ('od0ohCha'); | |
INSERT INTO foo (name) VALUES ('Eez3pee3'); | |
INSERT INTO foo (name) VALUES ('ohxaaPh5'); | |
INSERT INTO foo (name) VALUES ('uGhaiF3m'); | |
INSERT INTO foo (name) VALUES ('que9eRee'); | |
INSERT INTO foo (name) VALUES ('oso9Wo8b'); | |
INSERT INTO foo (name) VALUES ('Phe5tae4'); | |
INSERT INTO foo (name) VALUES ('LohtaQu8'); | |
INSERT INTO foo (name) VALUES ('Ce5caiz0'); | |
INSERT INTO foo (name) VALUES ('IaZo4Kai'); | |
update foo set uuid = UUID(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a reproduction scenario for the problem described in the comments on https://stackoverflow.com/a/34401374/53538 - how
UPDATE
causes all UUIDs to be the same.To run, put all 3 files in the same directory and run
make
. Built and tested on Ubuntu 20.04.Asciinema of me running this is at https://asciinema.org/a/wiUgn77W0PkbWHfgJktBph0WW