我這裡安裝的是8.0.25的版本。
1、擷取MySQL的Docker鏡像
docker pull mysql:8.0.25
2、重新打TAG并上傳Harbor伺服器
重新打TAG
docker tag mysql:8.0.25 10.248.245.184/mysql/release:8.0.25
上傳Harbor
docker push 10.248.245.184/mysql/release:8.0.25
3、啟動MySQL
登陸伺服器,并下載下傳鏡像
docker pull 10.248.245.184/mysql/release:8.0.25
在啟動之前初始化MySQL的配置,建立檔案路徑
sudo mkdir /home/mysql/conf.d
在建立的檔案夾下面添加如下配置檔案
docker.cnf檔案
[mysqld]
skip-host-cache
skip-name-resolve
default_authentication_plugin = mysql_native_password
mysql.cnf檔案
# Copyright (c) 2015, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysql]
啟動指令(我們把配置目錄挂在出來)
docker run --name mysql -p 15672:3306 -v /home/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=mysqlpwd123 -d 10.248.245.184/mysql/release:8.0.25
以上mysql的基礎版本就安裝完了。如果想建立使用者可以參考《MySQL - 使用root權限建立使用者》
使用中遇到的問題總結
1、錯誤 《MySQL - Navicat連接配接報2059 - Authentication plugin 'caching_sha2_password' cannot be loaded》
2、使用root使用者登陸報 1045 - Access denied for user 'root'@'10.177.16.209' (using password: YES) 。如果報的是這個錯誤,需要檢視上面的配置檔案中default_authentication_plugin = mysql_native_password配置是否丢失。
參考位址: https://hub.docker.com/_/mysql