我有使用mysql/mysql-server docker鏡像的問題。 我想連接到MySQL服務器,創建數據庫,用戶與所有特權有能力創建新的架構,並在未來運行liquibase。無法連接到mysql docker鏡像
我運行容器是這樣的:
sudo docker run --name db -e MYSQL_ROOT_PASSWORD=qwe123 -e MYSQL_DATABASE=test \
-d -p 3306:3306 mysql/mysql-server:5.6 --lower-case-table-names=1
當我做docker ps
我看到它的運行,但是當我試圖運行liquibase(用root/qwe123),它與失敗:
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project db: null, message from server: "Host '172.17.0.1' is not allowed to connect to this MySQL server" -> [Help 1]
試圖與用戶:
sudo docker run --name db -e MYSQL_ROOT_PASSWORD=qwe123 -e MYSQL_DATABASE=test \
-e MYSQL_USER=admin -e MYSQL_PASSWORD=qwe123 -d -p 3306:3306 \
mysql/mysql-server:5.6 --lower_case_table_names=1
與管理員用戶有錯誤創造新的模式,它貌似管理員只測試數據庫的訪問:
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project db: Access denied for user 'admin'@'%' to database 'test2' -> [Help 1]
與根以下錯誤:
[ERROR] The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
也試過設置權限在init命令管理:
docker run --name db -e MYSQL_ROOT_PASSWORD=qwe123 -e MYSQL_DATABASE=test -d \
-p 3306:3306 mysql/mysql-server:5.6 --lower_case_table_names=1 \
'--init-connect=CREATE USER `admin`@`localhost` IDENTIFIED BY "qwe123"; GRANT ALL PRIVILEGES ON *.* TO `admin`@`localhost` WITH GRANT OPTION; CREATE USER `admin`@`%` IDENTIFIED BY "qwe123";GRANT ALL PRIVILEGES ON *.* TO `admin`@`%` WITH GRANT OPTION;FLUSH PRIVILEGES;'
在這情況下爲根用戶有錯誤:
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project db: null, message from server: "Host '172.17.0.1' is not allowed to connect to this MySQL server" -> [Help 1]
的管理員 - 以下內容:
12:13:57 [ERROR] The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
還試圖用本地主機,127.0.0.1作爲主機數據庫,總是有誤差的連接。 任何想法?
除非你使用的是這裏沒有提到對數據的外部存儲卷,每個'搬運工run'可以創建新的數據訪問商店。你可能想嘗試使用'docker exec'而不是'docker run'運行'CREATE USER'嘗試。這將使用已經運行的容器,而不是創建另一個新的容器。 –
難點在於我想在Jenkins工作中運行Docker鏡像。 而在詹金斯,我無法爲docker exec打開-ti模式。 –
所以,我可以這樣添加用戶: '須藤搬運工運行--name分貝-e MYSQL_ROOT_PASSWORD = qwe123 -e MYSQL_DATABASE =測試-d -p 3306:3306的MySQL/MySQL的服務器:5.6 --lower的病例表 - names = 1 docker exec -ti db mysql -uroot -pqwe123 CREATE USER'admin' @'localhost' IDENTIFIED BY「qwe123」; 授予*。*到'admin' @'localhost'的所有特權與授予選項; CREATE USER'admin' @'%'IDENTIFIED BY「qwe123」; 授予*上的所有特權。*使用授權選項到'admin' @'%' FLUSH PRIVILEGES;' –