Mycat2 phần 1
Các công cụ phân tách đọc-ghi MySQL mã nguồn mở mà cá nhân tác giả đã dùng thử bao gồm Amoeba, MySQL Proxy, Mycat, v.v. Sau khi thử nghiệm và so sánh cẩn thận, Mycat đã được chọn làm công cụ proxy để phân tách đọc-ghi cơ sở dữ liệu MySQL trong một dự án thực tế. Phiên bản mới nhất hiện tại của Mycat là Mycat 2 , có sẵn từ http://dl.mycat.org.cn/2.0/install-template để lấy gói tải xuống.
1.Cài đặt Mycat 2
Cài đặt trên Window
Cài đặt MySQL 8.0.x.x
Cài đặt JDK1.8 và thêm vào path. (Lưu ý: Mycat2 chỉ hoạt động trên jdk1.8)
Vào trang chủ Mycat2 , truy cập như hình bên dưới:
ở đây chúng ta cần tải 2 gói: mycat2-1.21-realease-jar-with-dependencies.jar
và mycat2-install-template-1.21.zip
trong thư mục bên dưới:
- Giải nén file
mycat2-install-template-1.21.zip
và đặt gói jar xuống dưới thư mục lib của mycat2.
mycat2
|_bin
|_conf
|_datasources
|_users
|_lib
|_mycat2-1.21.jar
|_logs
Config lại file cấu hình trong datasources.
// prototypeDs.datasource.json { "dbType":"mysql", "idleTimeout":60000, "initSqls":[], //Default: false, whether to execute initSqls every time jdbc gets a connection "initSqlsGetConnection":true, "instanceType":"READ_WRITE", // Optional value: READ_WRITE,READ,WRITE "maxCon":1000, /* Unit millis, the main function of the timer in the configuration is to regularly check idle connections */ "maxConnectTimeout":3000, "maxRetryCount":5, "minCon":1, "name":"prototypeDs", "password":"123456", "type":"JDBC", "url":"jdbc:mysql://localhost:3306/mysql?useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8", "user":"mycat", // Username will be displayed "weight":0 // Weights specific to load balancing }
Config lại file cấu hình trong users, chỉnh lại username và password giống với tài khoản mysql.
// root.user.json { "dialect": "mysql", "ip": null, "password": "root", "transactionType": "proxy", "username": "root" }
Để khởi động mycat2 vào thư mục bin, mở Terminal với quyền Admin.
cd mycat/bin ./mycat start ./mycat status ./mycat start ./mycat stop ./mycat console ./mycat install // Added to system autostart (not yet implemented) ./mycat remove // Cancel automatic startup with the system (not yet implemented) ./mycat restart ./mycat pause ./mycat status
Nếu chạy thành công, khi vào navicat ta sẽ thấy mycat:
Hãy nhớ rằng cổng mặc định là để tạo kiểm tra cơ sở dữ liệu, tạo bảng, sau đó thêm dữ liệu và làm mới cơ sở dữ liệu mysql vật lý. Bạn sẽ thấy rằng các bảng cơ sở dữ liệu và dữ liệu được tạo trên mycat sẽ được đồng bộ hóa với mysql thực được liên kết.