docker 安裝MySQL遠端連線

來源:互聯網
上載者:User

標籤:連結   成功   cad   oracle   mon   nav   amp   local   csdn   

1. 下載Mysql的Docker鏡像:

  1. $ docker search mysql (搜尋mysql鏡像)  
  2. $ docker pull mysql (下載mysql鏡像,預設最新版本)  

2. 運行鏡像,設定root帳號初始密碼(123456),映射本地宿主機連接埠3306到Docker連接埠3306。測試過程沒有掛載本機資料盤:

  1. $ docker run -it --rm --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql  

3. 查看已啟動並執行容器:

  1. $ docker ps -a  
  2. CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES  
  3. a42f31094df5        mysql               "docker-entrypoint.s…"   7 seconds ago       Up 6 seconds        0.0.0.0:3306->3306/tcp   mysql  

4. 進入mysql容器:

  1. docker exec -it mysql bash  
  2. [email protected]:/#   

5. 在容器內登陸Mysql:

  1. [email protected]:/# mysql -uroot -p123456 或 (mysql -uroot -p ) 
  2. mysql: [Warning] Using a password on the command line interface can be insecure.  
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 9  
  5. Server version: 8.0.11 MySQL Community Server - GPL  
  6.   
  7. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.  
  8.   
  9. Oracle is a registered trademark of Oracle Corporation and/or its  
  10. affiliates. Other names may be trademarks of their respective  
  11. owners.  
  12.   
  13. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.  
  14.   
  15. mysql>   

6. 查看使用者資訊

  1. mysql> select host,user,plugin,authentication_string from mysql.user;    
  2. +-----------+------------------+-----------------------+------------------------------------------------------------------------+  
  3. | host      | user             | plugin                | authentication_string                                                  |  
  4. +-----------+------------------+-----------------------+------------------------------------------------------------------------+  
  5. | %         | root             | caching_sha2_password | $A$005$^]RQB}j~t!      .#v)3.UogPRFu8VJA5/GKEbK5edEQlMT5sHw2n72zYJNlIbo3 |  
  6. | localhost | mysql.infoschema | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |  
  7. | localhost | mysql.session    | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |  
  8. | localhost | mysql.sys        | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |  
  9. | localhost | root             | caching_sha2_password | $A$005$Y6&q!59^Fmh)@-6TG58J3F5+3I/HI9L|JCadNG+-+d6W+1D_UFW+7MRD7F3 |  
  10. +-----------+------------------+-----------------------+------------------------------------------------------------------------+  

備忘:host為 % 表示不限制ip   localhost表示本機使用    plugin非mysql_native_password 則需要修改密碼

navicat連結錯誤;我們繼續往下看;

 

 
  1. mysql> ALTER user ‘root‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘123456‘;  
  2. Query OK, 0 rows affected (0.01 sec)  
  3. mysql>   
  4. mysql> FLUSH PRIVILEGES;  
  5. Query OK, 0 rows affected (0.01 sec)  
  6.   
  7. mysql>   

7..串連資料庫的

 

 

 

串連成功了。

docker 安裝MySQL遠端連線

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.