人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

Docker 部署 Mysql8.0的方法示例

發(fā)布日期:2022-01-15 11:42 | 文章來源:CSDN

1. 參照官網,安裝docker

2.拉取mysql鏡像 (默認拉取最新的鏡像)8.0.11

docker pull mysql

3.在宿主機創(chuàng)建持久化 mysql data 及mysql.cnf

mkdir /usr/local/mysqlData/test/cnf
mkdir /usr/local/mysqlData/test/data
vi /usr/loal/mysqlData/test/cnf/mysql.cnf

設置本地文件共享:

Docker -> Preferences... -> File Sharing


4.添加操作權限

chmod 777 /usr/local/mysqlData/test/data 備注:掛載時權限驗證(操作權限)

5.運行鏡像,設置初始密碼、本機與docker端口的映射與掛載本地數(shù)據(jù)盤 (啟動msyql服務)

docker run -itd -p 3307:3306 --name test_mysql -v /usr/local/mysqlData/test/conf:/etc/mysql
 -v /usr/local/mysqlData/test/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql

運行結果:


6. 進入test_mysql 容器

Docker exec -it test_mysql bash

如圖:

7.在容器內登錄mysql


8.查看用戶信息

mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user       | host   | authentication_string                         |
+------------------+-----------+------------------------------------------------------------------------+
| root       | %     | $A$005$7o{'|'AomAw(QvF#.p5wLtCnrG6yX6XQdDVQivGr96POVL.gKnhIAhUhl3. |
| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE               |
| mysql.session  | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE               |
| mysql.sys    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE               |
| root       | localhost | $A$005$0.-%i)H{uYi@zFo7uYF82fYw7DsA93vYLr4uZv6I1tSKao0sbzzcDap3 |
+------------------+-----------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

9.設置權限(為root分配權限,以便可以遠程連接)

mysql> grant all PRIVILEGES on *.* to root@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

10.由于Mysql5.6以上的版本修改了Password算法,這里需要更新密碼算法,便于使用Navicat連接

mysql> grant all PRIVILEGES on *.* to root@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER user 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.11 sec)
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.11 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

11. 使用navicat 連接mysql,如圖:



12.建庫、建表、加數(shù)據(jù)




查看掛載本地數(shù)據(jù)盤的內容:


13. 測試將容器移除后,數(shù)據(jù)是否仍然存在

docker rm -f test_msyql


容器已經移除了。重新部署test_mysql,參照第5的步驟,進入新容器,訪問數(shù)據(jù)庫:

xushijiandeiMac:data xushijian$ docker run -itd -p 3307:3306 --name test_mysql -v /usr/local/mysqlData/test/conf:/etc/mysql -v /usr/local/mysqlData/test/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
65b7a60050aaef5765ed055acfd071c7c76f60e85dc25d0e73e0d56eae14aed1
xushijiandeiMac:data xushijian$ docker exec -it test_mysql bash
root@65b7a60050aa:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 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.
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
| test        |
+--------------------+
5 rows in set (0.01 sec)
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user_user;
+---------+-----------+-------------+--------+
| user_id | user_name | phone    | note  |
+---------+-----------+-------------+--------+
|    1 | 沒長正 | 13980000000 | 測試 |
+---------+-----------+-------------+--------+
1 row in set (0.06 sec)

發(fā)現(xiàn)數(shù)據(jù)仍然可以使用,不需要額外的配置,實現(xiàn)了數(shù)據(jù)的持久化。

阿里云上docker 部署 MySQL(通過編排模板部署)

<1. 配置同第3步類似(只是目錄變化)

master:
 image: 'mysql:latest'
 environment:
  - MYSQL_ROOT_PASSWORD=123456
 ports:
  - '3307:3306/tcp'
 volumes:
  - '/usr/local/mysqlData/master/conf:/etc/mysql:rw'
  - '/usr/local/mysqlData/master/data:/var/lib/mysql:rw'
 labels:
  aliyun.scale: '1'

<2.如下圖,已部署完成

[root@c13a6d832fd0a49398c62002361d75c60-node1 ~]# clear
[root@c13a6d832fd0a49398c62002361d75c60-node1 ~]# docker ps
CONTAINER ID    IMAGE      COMMAND         CREATED       STATUS       PORTS                      NAMES

8597b7539a3a    mysql:latest  "docker-entrypoint..."  3 minutes ago    Up 3 minutes    0.0.0.0:3307->3306/tcp              mysql_master_1


<3.進入容器,進行權限設置,后續(xù)過程參照本機

[root@c13a6d832fd0a49398c62002361d75c60-node1 /]# docker exec -it mysql_master_1 bash
root@2fc0bbf48941-mysql-master-1:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 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.
mysql> 

<4. 開放3307端口,使得外網可以訪問

云服務器ECS -> 安全組 -> 選擇所在的地區(qū) ->配置規(guī)則 -> 添加安全組


添加安全組,如圖:


5.外網訪問,如下圖


已連接成功。

主從環(huán)境搭建:

主庫:

[root@c13a6d832fd0a49398c62002361d75c60-node1 ~]# docker exec -it mysql_master_1 bash
root@2fc0bbf48941-mysql-master-1:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.11 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.
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
+--------------------+
4 rows in set (0.30 sec)
mysql> create database test;
Query OK, 1 row affected (0.12 sec)
mysql> show database;
ERROR 1064 (42000): 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 'database' at line 1
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
| test        |
+--------------------+
5 rows in set (0.00 sec)

從庫:

[root@c13a6d832fd0a49398c62002361d75c60-node1 ~]# docker exec -it mysql-slave_slave_1 bash
root@c8661e16e3fd-mysql-slave-slave-1:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.11 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.
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
+--------------------+
4 rows in set (0.40 sec)
mysql> show slave status\G
*************************** 1. row ***************************
        Slave_IO_State: Waiting for master to send event 主從配置成功!
         Master_Host: 47.94.225.124
         Master_User: rep
         Master_Port: 3307
        Connect_Retry: 60
       Master_Log_File: binlog.000003
     Read_Master_Log_Pos: 155
        Relay_Log_File: c8661e16e3fd-mysql-slave-slave-1-relay-bin.000004
        Relay_Log_Pos: 363
    Relay_Master_Log_File: binlog.000003
       Slave_IO_Running: Yes
      Slave_SQL_Running: Yes
       Replicate_Do_DB: 
     Replicate_Ignore_DB: 
      Replicate_Do_Table: 
    Replicate_Ignore_Table: 
   Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
          Last_Errno: 0
          Last_Error: 
         Skip_Counter: 0
     Exec_Master_Log_Pos: 155
       Relay_Log_Space: 762
       Until_Condition: None
        Until_Log_File: 
        Until_Log_Pos: 0
      Master_SSL_Allowed: No
      Master_SSL_CA_File: 
      Master_SSL_CA_Path: 
       Master_SSL_Cert: 
      Master_SSL_Cipher: 
        Master_SSL_Key: 
    Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
        Last_IO_Errno: 0
        Last_IO_Error: 
        Last_SQL_Errno: 0
        Last_SQL_Error: 
 Replicate_Ignore_Server_Ids: 
       Master_Server_Id: 1
         Master_UUID: a482f5fe-80fb-11e8-9fb1-0242ac12020c
       Master_Info_File: mysql.slave_master_info
          SQL_Delay: 0
     SQL_Remaining_Delay: NULL
   Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
      Master_Retry_Count: 86400
         Master_Bind: 
   Last_IO_Error_Timestamp: 
   Last_SQL_Error_Timestamp: 
        Master_SSL_Crl: 
      Master_SSL_Crlpath: 
      Retrieved_Gtid_Set: 
      Executed_Gtid_Set: 
        Auto_Position: 0
     Replicate_Rewrite_DB: 
         Channel_Name: 
      Master_TLS_Version: 
    Master_public_key_path: 
    Get_master_public_key: 0
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
+--------------------+
4 rows in set (1.01 sec)
mysql> show database;
ERROR 1064 (42000): 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 'database' at line 1
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| performance_schema |
| sys        |
| test        |
+--------------------+
5 rows in set (0.00 sec)

主從庫原理分析:


i/o線程去請求主庫 的binlog,并將得到的binlog日志寫到relay log(中繼日志) 文件中; 主庫會生成一個 log dump 線程,用來給從庫 i/o線程傳binlog;

SQL 線程,會讀取relay log文件中的日志,并解析成具體操作,來實現(xiàn)主從的操作一致,而最終數(shù)據(jù)一致;

即: 從庫IO線程請求 -> 中繼日志 ->獲取binlog ->從庫SQL線程,解析

參考:

https://docs.docker.com/docker 官網文檔

https://blog.csdn.net/gf0515/article/details/80466213Mac Navicat連接Docker MySql8.0

docker mysql 主從復制

https://blog.csdn.net/qq_28804275/article/details/80891951主從環(huán)境搭建

docker mysql Dockerfilemysql 開源鏡像Dockerfile及配置

https://www.cnblogs.com/Aiapple/p/5792939.html主從復制原理、高可用分析

http://www.cnblogs.com/Aiapple/p/5793786.html實戰(zhàn)

到此這篇關于Docker 部署 Mysql8.0的方法示例的文章就介紹到這了,更多相關Docker 部署 Mysql8.0內容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持本站!

版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網友推薦、互聯(lián)網收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務

7x24全年不間斷在線

專屬顧問服務

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務熱線

關注
微信

關注官方微信
頂部