docer學習之 mysql 鏡像安裝及啓動

docker容器安裝成功後,如果需要安裝mysql鏡像,則:

  1. 搜索mysql鏡像,可以在瀏覽器中去 docker hub 官網搜索mysql對應的鏡像及其 tag
[root@localhost sysconfig]# docker search mysql
  1. 選擇合適的版本號,使用 docker pull mysql 命令安裝,如果要指定版本則直接在後面加上版本號,如果不加,則默認安裝 latest 最新版本。
[root@localhost sysconfig]# docker pull mysql
  1. 安裝完成後,查看docker 鏡像 docker images , 該命令會列出 docker 容器中的所有鏡像,包括剛纔安裝的mysql
[root@localhost sysconfig]# docker images
  1. 啓動mysql:
#啓動命令: docker run --name 自己起的名字 -e MYSQL_ROOT_PASSWORD='密碼' -p 本機端口:容器端口 -d mysql
#其中: -e 指定mysql啓動的密碼參數,可以參照官網。
		--name  指定一個啓動的名字
		-p 端口映射,如果不映射,則虛擬機外部訪問不到該端口
		-d 後臺運行
[root@localhost sysconfig]# docker run --name mysql01 -e MYSQL_ROOT_PASSWORD='123456' -p 3306:3303 -d mysql

啓動後客戶端會顯示出啓動的容器鏡像id,說明啓動mysql 成功。
5. 使用 navicat 連接剛纔啓動的mysql,報 2059 的錯誤, 錯誤如下:

ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password'
 cannot be loaded: ÕÒ²»µ½Ö¸¶¨µÄÄ£¿é¡£

解決辦法:

  1. 進入mysql 命令行:
# 
[root@localhost sysconfig]# docker exec -it mysql01 /bin/bash

  1. 輸入 mysql -u root -p 進行登錄
# 輸入 mysql -u root -p 進行登錄
root@5368bf2b1025:/# mysql -u root -p
Enter password: 


# 登錄成功後出現如下
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  1. 使用以下命令修改密碼的加密方式。
# 使用一下命令修改密碼的加密方式。
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.07 sec)
  1. 重新連接即可。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章