想不进入 mysql 容器内执行 sql 语句(命令行执行是没问题的):
CREATE USER 'root'@'%' IDENTIFIED BY 'abcd1234';
GRANT ALL ON *.* TO 'root'@'%';
宿主机执行:
docker exec -it mysql bash -c 'mysql <<< "CREATE USER 'root'@'%' IDENTIFIED BY 'abcd1234';GRANT ALL ON *.* TO 'root'@'%';"'
ERROR 1064 (42000) at line 1: 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 '% IDENTIFIED BY abcd1234' at line 1
报语法错误,引号太多了,我仔细看,感觉也没毛病,但确实是执行不了,各位帮忙看一下,多谢了