www.bortolotto.eu

Newsfeeds
Planet MySQL
Planet MySQL - https://planet.mysql.com

  • A Practical Guide to Adding and Updating MySQL Replication Filters
    Managing MySQL replication filters in a live production environment doesn’t have to mean rebuilding your replicas from scratch. In this post, we’ll walk through how to safely exclude specific tables from replication and cleanly re-sync and add live tables back into the replication stream using mydumper and binlog coordinates, without ever touching the primary server. Why use replication filters? In MySQL, the primary-replica (formerly master-slave) architecture is the most widely used deployment pattern. Replication filters let you build replicas that hold only the data a team needs. Some teams need transaction data, others need analytics data, and a multi-source replica may combine data from several sources. Replicating less also reduces resource use. Needs change over time, so you will often have to update a replica’s filters, either to stop replicating some tables or schemas, or to start replicating them again. Ignoring a table on the replica is a quick filter change Stopping replication for the tables/schemas is easy. Just stop the replication, add/update the tables/schemas in the replication filters, and start the replication. See the example below to stop replication for the table sbtest.sbtest3.  Example: Replication status before adding the filters:*************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000023 Read_Source_Log_Pos: 802000814 Relay_Log_File: ip-172-31-88-61-relay-bin.000012 Relay_Log_Pos: 285467877 Relay_Source_Log_File: binlog.000022 Replica_IO_Running: Yes Replica_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 285467666 Relay_Log_Space: 1875763218 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Source: 868 Last_IO_Error: Last_SQL_Error:Adding the table sbtest.sbtest3 to the replication filters:mysql> STOP REPLICA; Query OK, 0 rows affected (0.02 sec) mysql> CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE = (sbtest.sbtest3); Query OK, 0 rows affected (0.00 sec) mysql> START REPLICA; Query OK, 0 rows affected (0.01 sec) mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000023 Read_Source_Log_Pos: 945759470 Relay_Log_File: ip-172-31-88-61-relay-bin.000012 Relay_Log_Pos: 342686043 Relay_Source_Log_File: binlog.000022 Replica_IO_Running: Yes Replica_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 342685832 Relay_Log_Space: 2019522262 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Source: 914 Last_IO_Error: Last_SQL_Error: Check that the table gets no more writes Hashing the same value three times means the table is no longer receiving writes from the primary.mysql> pager md5sum; PAGER set to 'md5sum' mysql> select * from sbtest.sbtest3; b3454182d67ebeb29a453cc18f5d50e6 - 100000 rows in set (0.38 sec) mysql> select * from sbtest.sbtest3; b3454182d67ebeb29a453cc18f5d50e6 - 100000 rows in set (0.07 sec) mysql> select * from sbtest.sbtest3; b3454182d67ebeb29a453cc18f5d50e6 - 100000 rows in set (0.07 sec) Why restoring a dump isn’t enough for a live table? When the requirement is to add or update a table or database in the filters to replicate data from the primary to the replica, we need to work carefully; a small mistake can cause a replication error on the replica, and we may end up rebuilding it from scratch. For this, we usually think that just taking a dump backup from the primary or another replica and restoring it on the replica may work. But this will not be enough for the live tables/databases. We also need to stop the replication and start replication with the correct file/position. The high-level plan for this task is below. Stop replication on the target replica where filters need to be added or updated. Take a consistent mydumper backup from the primary or another suitable replica. Make sure to capture the primary’s binlog file and position corresponding to the backup snapshot. Start replication on the  target replica until the binlog file  and position we got from mydumper Restore the dump on the target replica Add/update the replication filter on the target replica. Start the replication Here is an example of how I added the table sbtest.sbtest3  back into the replication.  Step 1: Stop replication cleanly on the target replica The target replica uses multi-threaded replication. START REPLICA UNTIL SQL_AFTER_MTS_GAPS lets the parallel applier threads fill any gaps, ensuring the replica’s position is consistent, after which the SQL thread stops automatically. With a single applier thread, you can skip this and run STOP REPLICA.mysql> STOP REPLICA; Query OK, 0 rows affected (0.01 sec) mysql> START REPLICA UNTIL SQL_AFTER_MTS_GAPS; Query OK, 0 rows affected (0.01 sec) mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000026 Read_Source_Log_Pos: 660328628 Relay_Log_File: ip-172-31-88-61-relay-bin.000017 Relay_Log_Pos: 212025835 Relay_Source_Log_File: binlog.000023 Replica_IO_Running: Yes Replica_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 904847198 Relay_Log_Space: 3881619155 Until_Condition: DONE Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Source: NULLmysql> stop replica; Query OK, 0 rows affected (0.01 sec) mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000026 Read_Source_Log_Pos: 665926304 Relay_Log_File: ip-172-31-88-61-relay-bin.000017 Relay_Log_Pos: 212025835 Relay_Source_Log_File: binlog.000023 Replica_IO_Running: No Replica_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 904847198 Relay_Log_Space: 3887216831 Until_Condition: DONE Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Source: NULL Last_IO_Error: Last_SQL_Error: Step 2: Take a mydumper backup from another replica Take a dump from another replica using mydumper with the –replica-data option to capture the primary’s binlog file and position. This allows you to avoid touching the primary.root@ip-172-31-88-61:/home/ubuntu# mydumper --host=172.31.94.154 -u root -p Percona@1234 --tables-list=sbtest.sbtest3 --trx-tables --threads=4 --outputdir=/tmp/mydump_export --replica-data ** (mydumper:13763): WARNING **: 07:03:16.178: Using --trx-tables options, binlog coordinates will not be accurate if you are writing to non transactional tables. root@ip-172-31-88-61:/home/ubuntu# echo $? 0 root@ip-172-31-88-61:/home/ubuntu# ls -lrth /tmp/mydump_export total 19M -rw-r----- 1 root root 405 Oct 31 07:03 sbtest-schema-create.sql -rw-r----- 1 root root 548 Oct 31 07:03 sbtest.sbtest3-schema.sql -rw-r----- 1 root root 4.8M Oct 31 07:03 sbtest.sbtest3.00002.sql -rw-r----- 1 root root 4.8M Oct 31 07:03 sbtest.sbtest3.00000.sql -rw-r----- 1 root root 5.4M Oct 31 07:03 sbtest.sbtest3.00001.sql -rw-r----- 1 root root 4.2M Oct 31 07:03 sbtest.sbtest3.00003.sql -rw-r--r-- 1 root root 2.6K Oct 31 07:03 metadata root@ip-172-31-88-61:/home/ubuntu#The metadata file records where the primary’s binary log was when the dump was taken. We need that position for the next step, to stop the target replica at the same point.root@ip-172-31-88-61:/home/ubuntu# cat /tmp/mydump_export/metadata # Started dump at: 2026-10-31 07:03:16 [config] quote-character = BACKTICK [myloader_session_variables] SQL_MODE='NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' /*!40101 [source] # Channel_Name = '' # It can be use to setup replication FOR CHANNEL # SOURCE_LOG_FILE = "ip-172-31-94-154-bin.000006" # SOURCE_LOG_POS = 655712715 [replication] SOURCE_LOG_FILE = "binlog.000024" SOURCE_LOG_POS = 950744300 #SOURCE_AUTO_POSITION = {0|1} # Replica_IO_State = 'Waiting for source to send event' # Source_Host = '172.31.92.195' # Source_User = 'repl_user' # Source_Port = 3306 # Connect_Retry = 60 Step 3: Start replication until the dump’s position Get the primary binlog and position from the metadata file, start replication until the primary binlog and position match, and wait a while for it to sync with the file and position.mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000026 Read_Source_Log_Pos: 665926304 Relay_Log_File: ip-172-31-88-61-relay-bin.000017 Relay_Log_Pos: 212025835 Relay_Source_Log_File: binlog.000023 Replica_IO_Running: No Replica_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 904847198 Relay_Log_Space: 3887216831 Until_Condition: DONE Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Source: NULL Last_IO_Error: Last_SQL_Error: mysql> START REPLICA UNTIL SOURCE_LOG_FILE='binlog.000024', SOURCE_LOG_POS=950744300; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000026 Read_Source_Log_Pos: 722233290 Relay_Log_File: ip-172-31-88-61-relay-bin.000017 Relay_Log_Pos: 213572791 Relay_Source_Log_File: binlog.000023 Replica_IO_Running: Yes Replica_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 906394154 Relay_Log_Space: 3943524205 Until_Condition: Source Until_Log_File: binlog.000024 Until_Log_Pos: 950744300 Seconds_Behind_Source: 2986 Last_IO_Error: Last_SQL_Error:After some time, the SQL thread stopped once it reached the file and positionmysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000030 Read_Source_Log_Pos: 964722776 Relay_Log_File: ip-172-31-88-61-relay-bin.000020 Relay_Log_Pos: 950744511 Relay_Source_Log_File: binlog.000024 Replica_IO_Running: Yes Replica_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 950744300 Relay_Log_Space: 7407279616 Until_Condition: Source Until_Log_File: binlog.000024 Until_Log_Pos: 950744300 Seconds_Behind_Source: NULL Last_IO_Error: Last_SQL_Error: Step 4: Restore the dump on the target replica Restore the dump to the target replica where we need to update the filters. The replication SQL thread is paused at the dump’s position, so the restore won’t conflict with any changes the replica is applying.root@ip-172-31-88-61:/home/ubuntu# myloader --database=sbtest --directory=/tmp/mydump_export --threads=4 -o --queries-per-transaction=5000 -u root -p Percona@1234 root@ip-172-31-88-61:/home/ubuntu# echo $? 0 root@ip-172-31-88-61:/home/ubuntu#mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000031 Read_Source_Log_Pos: 384516500 Relay_Log_File: ip-172-31-88-61-relay-bin.000020 Relay_Log_Pos: 950744511 Relay_Source_Log_File: binlog.000024 Replica_IO_Running: Yes Replica_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: sbtest.sbtest3 Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 950744300 Relay_Log_Space: 7900841683 Until_Condition: Source Until_Log_File: binlog.000024 Until_Log_Pos: 950744300 Seconds_Behind_Source: NULL Last_IO_Error: Last_SQL_Error: Step 5: Remove the table from the filter Remove the replication filter so it defaults to replicating all the data from the primary. mysql> stop replica; Query OK, 0 rows affected (0.01 sec) mysql> CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE = (); Query OK, 0 rows affected (0.00 sec) mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000031 Read_Source_Log_Pos: 391339868 Relay_Log_File: ip-172-31-88-61-relay-bin.000020 Relay_Log_Pos: 950744511 Relay_Source_Log_File: binlog.000024 Replica_IO_Running: No Replica_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 950744300 Relay_Log_Space: 7907665051 Until_Condition: Source Until_Log_File: binlog.000024 Until_Log_Pos: 950744300 Seconds_Behind_Source: NULL Last_IO_Error: Last_SQL_Error:In this example, there is a single table to remove, so I used empty braces. If multiple tables are added to the replication filter, you may need to remove the specific table while keeping the others. Example:CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE = (myschema.table1, myschema.table2, myschema.table3); Step 6: Start replication mysql> start replica; Query OK, 0 rows affected (0.03 sec) mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 172.31.92.195 Source_User: repl_user Source_Port: 3306 Source_Log_File: binlog.000031 Read_Source_Log_Pos: 416723216 Relay_Log_File: ip-172-31-88-61-relay-bin.000020 Relay_Log_Pos: 953071929 Relay_Source_Log_File: binlog.000024 Replica_IO_Running: Yes Replica_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Error: Exec_Source_Log_Pos: 953071718 Relay_Log_Space: 7933048787 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Source: 3756 Last_IO_Error: Last_SQL_Error:Verify that the table is receiving writes from the primary and that there are no replication errors. You can also use pt-table-checksum to verify the data consistency.mysql> pager md5sum; PAGER set to 'md5sum' mysql> select * from sbtest.sbtest3; 42b34b3393caab1ad5c897e3dd51452d - 100000 rows in set (0.08 sec) mysql> select * from sbtest.sbtest3; 9db2089cf1c0db893d36a9714f213364 - 100000 rows in set (0.06 sec) mysql> select * from sbtest.sbtest3; 15614dd6f04015a19b8df8c0bff69031 - 100000 rows in set (0.07 sec) mysql> show replica status\G af2a62818210a0ca679f3b29d3eb0832 - 1 row in set (0.00 sec)Please note the replication status output above is trimmed to make the blog post short. Conclusion This structured approach ensures data consistency while minimising maintenance overhead. I hope the above example gives ideas for how to play with replication filters and helps update MySQL replication in live production without ever touching the primary. Using the above approach, you can add/update multiple tables or schemas in the replication filters.  Please comment if you have any questions/comments. The post A Practical Guide to Adding and Updating MySQL Replication Filters appeared first on Percona.

  • Bài tập PHP và MySQL cho người mới: 8 bài thực hành
    Nếu bạn đang tự học lập trình web, gần như chắc chắn sẽ có lúc phải tự tay kết nối PHP với MySQL. Đội ngũ chúng tôi từng gặp nhiều bạn xem xong cả chục video hướng dẫn mà vẫn chưa tự viết nổi một trang đăng ký. Thường thì vấn đề không nằm ở độ khó của kiến thức, mà ở việc thiếu bài tập PHP và MySQL đúng sức để luyện tay. Vì vậy, chúng tôi gom lại 8 bài thực hành, đi từ kết nối cơ bản đến quan hệ giữa các bảng. Mỗi bài đều có hướng làm và những lỗi mà người mới hay vấp phải. Bài tập PHP và MySQL là gì và vì sao nên làm? Nói dễ hiểu, đây là những bài nhỏ trong đó PHP đóng vai người xử lý logic, còn MySQL là nơi cất giữ dữ liệu. Bạn nhập tên một học viên vào form. PHP nhận lấy, kiểm tra, rồi gửi xuống MySQL để ghi lại. Khi cần xem danh sách, PHP lại hỏi MySQL rồi trình bày kết quả ra trình duyệt. Làm đủ các bài này, bạn sẽ hình dung rõ luồng request và response. Trình duyệt gửi yêu cầu, server xử lý, rồi trả về một trang. Bạn cũng quen với việc kết nối cơ sở dữ liệu và bốn thao tác CRUD gồm thêm, xem, sửa, xoá. Đây là nền tảng mà hầu hết framework lớn đang làm ngầm bên dưới. Đối tượng phù hợp nhất là dev tự học và sinh viên mới vào nghề. Ngay cả khi bạn đã quen một framework, các bài này vẫn hữu ích vì chúng cho bạn biết framework đang làm gì phía sau mỗi dòng lệnh. Chuẩn bị môi trường để bắt đầu làm bài Bạn không cần máy chủ thật. Trên máy cá nhân, XAMPP hoặc Laragon là đủ. Hai phần mềm này gộp sẵn Apache để chạy PHP và MySQL để lưu dữ liệu. Sau khi cài, mở bảng điều khiển và bấm Start cho cả Apache lẫn MySQL. Nếu một trong hai chưa bật, gần như mọi bài tập về sau sẽ báo lỗi kết nối. Đây cũng là lỗi người mới gặp nhiều nhất. Để tạo bảng, bạn có thể dùng phpMyAdmin chạy sẵn trên trình duyệt, hoặc MySQL Workbench nếu thích giao diện desktop. Workbench hữu ích hơn khi bạn cần xem sơ đồ quan hệ giữa các bảng ở bài 6. Về editor, VS Code là lựa chọn phổ biến và nhẹ. Cấu trúc thư mục nên đơn giản: một thư mục dự án, một file kết nối riêng, và các trang PHP tách theo từng bài. Bài 1: Kết nối PHP với cơ sở dữ liệu Đây là bước đầu tiên, và cũng là bước nhiều người bỏ qua phần kiểm tra lỗi. Bạn có hai cách là PDO hoặc mysqli. PDO hỗ trợ nhiều loại cơ sở dữ liệu và dùng chung một kiểu viết. Viết file kết nối và bao quanh bằng try-catch để bắt lỗi. Sau đó chạy một câu SELECT đơn giản, chẳng hạn đếm số dòng trong một bảng thử. Nếu thấy kết quả hiện ra trên trang, bạn đã thông. Sai tên database. Sai mật khẩu (XAMPP mặc định thường để trống). Quên bật MySQL trong bảng điều khiển. Thông báo lỗi của PHP thường khá rõ ràng, nên hãy đọc kỹ dòng đầu tiên trước khi sửa code. Bài 2: Thao tác CRUD với bảng sinh viên CRUD là viết tắt của Create, Read, Update, Delete, tức là thêm, đọc, sửa, xoá. Bạn thiết kế một bảng students với các cột id, name, email và created_at. Cột id tự tăng, còn created_at tự lấy thời gian khi thêm bản ghi. Hãy hình dung bạn đang quản lý danh sách học viên của một lớp 30 người. Mỗi buổi có người nghỉ, có người đổi email, có người mới vào. Bạn sẽ dùng đúng bốn thao tác này cho công việc đó. Đừng vội chuyển sang bài sau khi chỉ mới thêm được dữ liệu. Hãy thử sửa một dòng và xoá một dòng, rồi kiểm tra lại trong phpMyAdmin xem dữ liệu có đúng không. Bài 3: Form đăng ký có kiểm tra dữ liệu Kiểm tra dữ liệu bằng JavaScript trên trình duyệt chỉ là lớp bảo vệ bề mặt, vì người dùng có thể tắt đi dễ dàng. Vì vậy bạn phải kiểm tra lại trên server. Email đúng định dạng. Tên không để trống. Email chưa tồn tại trong bảng. Khi viết truy vấn, hãy dùng prepared statement. Cách này tách câu lệnh SQL khỏi dữ liệu người dùng, giúp chống SQL injection, tức kiểu tấn công chèn lệnh SQL qua ô nhập. Một lỗi thường gặp là kiểm tra trùng email bằng truy vấn riêng nhưng quên ràng buộc UNIQUE trong bảng. Hãy làm cả hai, vì kiểm tra trong code có thể bị lọt khi hai người đăng ký cùng lúc. Bài 4: Tìm kiếm và phân trang dữ liệu Khi bảng có vài trăm dòng, hiển thị hết một lượt sẽ làm trang chậm và khó đọc. Phân trang chia dữ liệu thành từng trang nhỏ bằng LIMIT và OFFSET trong câu SELECT. Để tính số trang, lấy tổng số bản ghi chia cho số dòng mỗi trang rồi làm tròn lên. Phần tìm kiếm dùng LIKE kết hợp ký tự %, ví dụ tìm những tên có chứa một chuỗi nào đó. Muốn tìm kiếm nhanh hơn, hãy đánh index cho các cột hay được tìm như name hoặc email. Lưu ý là LIKE với % ở đầu chuỗi khó tận dụng index, nên với bảng lớn bạn cần cân nhắc cách tìm khác. Bài 5: Đăng nhập đơn giản Mật khẩu tuyệt đối không được lưu dạng chữ thường. Hãy dùng password_hash để băm mật khẩu trước khi ghi vào bảng, và password_verify để kiểm tra khi đăng nhập. Hai hàm này có sẵn trong PHP. Sau khi đăng nhập đúng, dùng session để ghi nhớ người dùng qua các trang. Nhớ gọi session_start() ở đầu mỗi trang cần kiểm tra. Khi đăng xuất, hãy xoá session và huỷ cookie tương ứng. Đừng hiện thông báo quá chi tiết kiểu “sai email” hay “sai mật khẩu” riêng biệt, vì điều đó giúp kẻ xấu dò tài khoản. Chỉ nên báo chung là thông tin không đúng. Bài 6: Quan hệ giữa các bảng và khoá ngoại Dữ liệu thực tế hiếm khi nằm trong một bảng duy nhất. Ví dụ một lớp học có nhiều sinh viên, mỗi sinh viên thuộc một lớp. Bạn tạo bảng classes và thêm cột class_id vào bảng students, rồi khai báo khoá ngoại trỏ về cột id của bảng lớp. Để hiển thị tên lớp cạnh tên sinh viên, bạn dùng JOIN. JOIN sai điều kiện sẽ làm kết quả bị nhân lên hoặc mất dòng mà không báo lỗi, nên hãy đếm số dòng sau mỗi lần viết để chắc chắn. Sai lầm hay gặp là quên tạo khoá ngoại, khiến MySQL cho phép ghi một class_id không tồn tại. Khoá ngoại lúc đầu có vẻ phiền, nhưng nó giữ cho dữ liệu nhất quán khi dự án lớn dần. Ưu và nhược điểm khi tự làm bài tập PHP và MySQL Ưu điểm rõ nhất là bạn hiểu sâu, nhớ lâu, và có sản phẩm để đưa vào portfolio. Hiểu sâu luồng xử lý và kết nối dữ liệu. Có dự án nhỏ để chứng minh kỹ năng. Nhược điểm là dễ rơi vào học thuộc code mà không hiểu logic. Cách cân bằng là xem mẫu một lần, đóng lại, rồi tự viết lại từ đầu. Chỗ nào phải nhìn lại chính là chỗ bạn chưa nắm chắc. Nguồn học và công cụ hỗ trợ Tài liệu chính thức luôn là nguồn đáng tin nhất. Bạn có thể tham khảo php.net cho PHP và dev.mysql.com cho MySQL. Để hiểu rõ cách MySQL tổ chức dữ liệu trước khi thực hành, bạn có thể xem thêm tổng quan về hệ quản trị cơ sở dữ liệu MySQL. Khi cần xem thêm các bài viết về bảo mật và thiết kế website, bạn có thể tham khảo MONA Media. Để tự kiểm tra kết quả, hãy so số dòng trong phpMyAdmin với số dòng trang web hiển thị, thử nhập dữ liệu sai để xem code có chặn không, và thử một lần tấn công đơn giản vào form của chính mình. Câu hỏi thường gặp Người mới nên làm bài tập PHP và MySQL trong bao lâu? Với người đã biết cú pháp PHP cơ bản, khoảng 3 đến 4 tuần làm đều tay là đủ cho 8 bài này. Nếu mới hoàn toàn, có thể mất gấp đôi thời gian. Nên dùng mysqli hay PDO cho bài tập? Chúng tôi thường khuyên dùng PDO vì cách viết thống nhất và dễ chuyển sang loại cơ sở dữ liệu khác về sau. Mysqli vẫn ổn nếu bạn chỉ dùng MySQL và muốn code gọn cho bài nhỏ. Làm bài tập trên Windows có khác macOS không? Phần code PHP và SQL gần như giống hệt nhau. Khác biệt nằm ở môi trường cài đặt: Windows thường dùng XAMPP hoặc Laragon, còn macOS có thể dùng MAMP. Làm sao biết code bài tập đã an toàn? Hãy kiểm tra ba điểm: mọi truy vấn có dữ liệu người dùng đã dùng prepared statement chưa, mật khẩu có được băm không, và trang quản trị có kiểm tra đăng nhập không. The post Bài tập PHP và MySQL cho người mới: 8 bài thực hành appeared first on DBAhire.

  • dbdeployer 2.5.0 is out: Try MySQL 9.7 and 26.7 in a sandbox
    Spin up MySQL 9.7 or 26.7 with dbdeployer, and keep four-part MySQL correction releases alongside the originals for side-by-side testing.

  • Percona Database Service Is Now Open Source
    We have some exciting news to share: Percona Database Service (PDS) is now open source! The source code is available on GitHub under the Apache 2.0 license, and we’ve also launched a redesigned PDS website to make it easier to explore and get started. When we first introduced PDS, our goal was simple: make deploying and managing open source databases easier without requiring users to give up control of their infrastructure or data. Now we’re taking the next step by opening the project to the community. What’s new? PDS is available on GitHub You can now explore the source code, experiment with the platform, suggest improvements, and contribute to its development. PDS is built on OpenEverest and Percona’s database operators. It provides a control plane for managing MySQL and PostgreSQL databases running on Kubernetes, with capabilities including: Database provisioning using predefined Dev, Staging, and Production profiles Scaling, backups, and restores Database monitoring with Percona Monitoring and Management (PMM) Private and controlled public database access Integration with Percona Support You can also run PDS locally using Docker and kind, without provisioning an AWS environment. The repository includes instructions for setting up a local development environment. A new home for PDS We’ve redesigned pds.percona.com to make it easier to discover what PDS can do, explore its capabilities, and start working with the platform. Database management meets AI agents We’re also exploring how database operations can become part of AI-assisted development workflows. PDS provides an MCP (Model Context Protocol) interface and integrations for tools such as Claude Code and Cursor. These allow AI agents to interact with PDS to provision databases, inspect their status, and perform supported management operations. Agent access is governed by explicit permissions and user authorization, including controls over changes and destructive operations. Help us shape what’s next PDS remains an experimental project in alpha, and we’re actively exploring its direction. We’re particularly interested in feedback from users. What works well? What’s missing? How could PDS fit into your development or operational workflows? Making PDS open source is an important step toward answering these questions together with the community. Ready to explore? Visit pds.percona.com to try PDS, or head to our GitHub repository to explore the code, run it locally, and contribute. We’d love to hear what you think. The post Percona Database Service Is Now Open Source appeared first on Percona.

  • Oracle’s November CSPU and Percona for MySQL
    Oracle published its November 2026 CSPU (Critical Security Patch Update) on November 17, with 10 new security patches for MySQL. Three of them can be exploited over the network without authentication. Percona tracks every Oracle security release, and we’re already working on this one. Oracle published the MySQL 8.4 and 9.7 source code for these fixes on November 24, and our engineering team has merged it and is testing the fixes now. Here’s what we know and what you can do. The three CVEs to look at first Most of the November 2026 CSPU fixes need an attacker who already has a MySQL account with privileges. These three do not, so start your risk review here. All details come from Oracle’s November 2026 CSPU advisory. CVE CVSS 3.1 Component Protocol Affected upstream versions CVE-2026-115557 9.8 MySQL Shell Core Client (Python) HTTP MySQL Shell 26.10.0 CVE-2026-114952 9.1 MySQL Server Client programs MySQL Protocol 8.4.0 to 8.4.13 9.7.0 to 9.7.4 26.10 CVE-2026-92392 8.1 MySQL Server Packaging (curl) HTTP/2 8.4.0 to 8.4.13 9.7.0 to 9.7.4 26.10 The other seven MySQL CVEs score between 2.5 and 7.2. Five of them are in the server (Replication, Optimizer, Logging, and GIS) and require an authenticated user. None of this is new territory. Oracle has published MySQL CVEs with the same scores and attack profile before. CVE-2026-115557 is similar to CVE-2025-15467, CVE-2025-6965, CVE-2026-46860, and CVE-2026-9547, and CVE-2026-114952 is similar to CVE-2024-11053. The next section covers where each fix stands for Percona Server for MySQL. Where the fixes stand in Percona Server for MySQL Percona Server for MySQL is built on Oracle’s upstream code, so we merge, test, and ship the fixes for each branch once Oracle releases its code. Oracle published the MySQL 8.4 and 9.7 code on November 24. MySQL Shell (CVE-2026-115557) This vulnerability is in the Python runtime that MySQL Shell bundles, not in the MySQL server. We’ve rebuilt the MySQL Shell packages we ship for Percona Server for MySQL 8.4 and 9.7 with a fixed Python, and they’re in testing now. curl (CVE-2026-92392) Oracle fixed this by upgrading the curl library it bundles with MySQL. Percona Server for MySQL packages use your operating system’s curl library instead of a bundled copy, so apply your OS vendor’s curl updates. Client programs (CVE-2026-114952) and the server CVEs The fixes are in the 8.4 and 9.7 code Oracle published, and we’ve merged them into Percona Server for MySQL 8.4 and 9.7. Releases The fixes will ship in Percona Server for MySQL and Percona XtraDB Cluster (PXC) 8.4.13-13 and 9.7.4-4 releases. This is the same process we follow for every Oracle CPU and CSPU. Each quarterly CPU this year and the June CSPU included high-severity MySQL fixes, and we delivered each of them in Percona Server for MySQL releases once the upstream code was out. What you can do now These are standard hardening steps, and they match the general workarounds in Oracle’s advisory. If you already follow them, your exposure is lower. None of them replaces the patch. No configuration change is confirmed to mitigate these CVEs yet. None of them involve X Protocol, so turning off X Plugin (mysqlx=OFF) won’t help with this CSPU. We’re reviewing the code now and will share any config-level mitigation we find. Restrict network access. Only known application hosts and admin networks should reach your MySQL ports. Block everything else at the firewall or security group. Tighten privileges. Most of these CVEs need an authenticated user. Remove accounts and grants nobody uses, especially broad admin and replication privileges. Update MySQL Shell and curl. Move to our rebuilt MySQL Shell packages once they’re released, and keep your operating system’s curl package current. Test before production. Network and privilege changes can break applications and replication. Try them in a non-production environment first. Next steps Start with the three unauthenticated CVEs, lock down network access and privileges, and watch this post for release details. The 8.4 and 9.7 fixes are merged into Percona Server for MySQL and in testing now. Need help assessing your exposure? Percona Expert Support for MySQL can review your configuration and plan the upgrade with you. If you’re already a Percona customer, reach out to your account team or open a support ticket. If not, contact us. The post Oracle’s November CSPU and Percona for MySQL appeared first on Percona.