{"id":197,"title":"SQL Notlar\u0131: partitioning, replication","content":"<p>MySQL, b\u00fcy\u00fck veri k\u00fcmelerini y\u00f6netmek ve y\u00fcksek kullan\u0131labilirlik sa\u011flamak i\u00e7in \u00e7e\u015fitli y\u00f6ntemler sunar. Bu yaz\u0131da, **b\u00f6l\u00fcmleme (partitioning)** ve **\u00e7o\u011faltma (replication)** kavramlar\u0131n\u0131 ele alaca\u011f\u0131z. Bu teknikler, veritaban\u0131 performans\u0131n\u0131 art\u0131rmak ve veri g\u00fcvenli\u011fini sa\u011flamak i\u00e7in olduk\u00e7a \u00f6nemlidir.<\/p><p>---<\/p><p>### B\u00f6l\u00fcmleme (Partitioning)<\/p><p>B\u00f6l\u00fcmleme, b\u00fcy\u00fck tablolar\u0131 daha k\u00fc\u00e7\u00fck ve y\u00f6netilebilir par\u00e7alara ay\u0131rma i\u015flemidir. Bu, sorgu performans\u0131n\u0131 art\u0131rabilir ve veri y\u00f6netimini kolayla\u015ft\u0131rabilir. MySQL'de \u00fc\u00e7 temel b\u00f6l\u00fcmleme t\u00fcr\u00fc vard\u0131r: **RANGE**, **LIST** ve **HASH**.<\/p><p>#### 1. RANGE B\u00f6l\u00fcmleme<br>RANGE b\u00f6l\u00fcmleme, belirli bir aral\u0131ktaki de\u011ferlere g\u00f6re verileri b\u00f6l\u00fcmlemek i\u00e7in kullan\u0131l\u0131r. \u00d6rne\u011fin, bir ma\u011faza zincirindeki \u00e7al\u0131\u015fanlar\u0131 ma\u011faza kimlik numaralar\u0131na g\u00f6re b\u00f6l\u00fcmleyebilirsiniz:<\/p><p>```sql<br>ALTER TABLE employees PARTITION BY RANGE (store_id) (<br>&nbsp; &nbsp;PARTITION p0 VALUES LESS THAN (6),<br>&nbsp; &nbsp;PARTITION p1 VALUES LESS THAN (11),<br>&nbsp; &nbsp;PARTITION p2 VALUES LESS THAN (16),<br>&nbsp; &nbsp;PARTITION p3 VALUES LESS THAN MAXVALUE<br>);<br>```<\/p><p>Bu \u00f6rnekte, `store_id` de\u011ferine g\u00f6re \u00e7al\u0131\u015fanlar d\u00f6rt farkl\u0131 b\u00f6l\u00fcme ayr\u0131lm\u0131\u015ft\u0131r.<\/p><p>#### 2. LIST B\u00f6l\u00fcmleme<br>LIST b\u00f6l\u00fcmleme, belirli bir de\u011fer listesine g\u00f6re verileri b\u00f6l\u00fcmlemek i\u00e7in kullan\u0131l\u0131r. \u00d6rne\u011fin, ma\u011fazalar\u0131 b\u00f6lgelere g\u00f6re b\u00f6l\u00fcmleyebilirsiniz:<\/p><p>```sql<br>ALTER TABLE employees PARTITION BY LIST(store_id) (<br>&nbsp; &nbsp;PARTITION pNorth VALUES IN (3, 5, 6, 9, 17),<br>&nbsp; &nbsp;PARTITION pEast VALUES IN (1, 2, 10, 11, 19, 20),<br>&nbsp; &nbsp;PARTITION pWest VALUES IN (4, 12, 13, 14, 18),<br>&nbsp; &nbsp;PARTITION pCentral VALUES IN (7, 8, 15, 16)<br>);<br>```<\/p><p>Bu \u00f6rnekte, her b\u00f6lgeye ait ma\u011faza kimlik numaralar\u0131 belirli b\u00f6l\u00fcmlere atanm\u0131\u015ft\u0131r.<\/p><p>#### 3. HASH B\u00f6l\u00fcmleme<br>HASH b\u00f6l\u00fcmleme, verileri belirli bir say\u0131da b\u00f6l\u00fcme e\u015fit olarak da\u011f\u0131tmak i\u00e7in kullan\u0131l\u0131r. Bu y\u00f6ntem, b\u00f6l\u00fcmleme i\u015flemini otomatik olarak ger\u00e7ekle\u015ftirir:<\/p><p>```sql<br>CREATE TABLE employees (<br>&nbsp; &nbsp;id INT NOT NULL,<br>&nbsp; &nbsp;fname VARCHAR(30),<br>&nbsp; &nbsp;lname VARCHAR(30),<br>&nbsp; &nbsp;hired DATE NOT NULL DEFAULT '1970-01-01',<br>&nbsp; &nbsp;separated DATE NOT NULL DEFAULT '9999-12-31',<br>&nbsp; &nbsp;job_code INT,<br>&nbsp; &nbsp;store_id INT<br>)<br>PARTITION BY HASH(store_id)<br>PARTITIONS 4;<br>```<\/p><p>Bu \u00f6rnekte, `store_id` s\u00fctununa g\u00f6re veriler d\u00f6rt b\u00f6l\u00fcme e\u015fit olarak da\u011f\u0131t\u0131l\u0131r.<\/p><p>---<\/p><p>### \u00c7o\u011faltma (Replication)<\/p><p>\u00c7o\u011faltma, bir veritaban\u0131 sunucusundaki verilerin bir veya daha fazla sunucuya kopyalanmas\u0131 i\u015flemidir. Bu, y\u00fcksek kullan\u0131labilirlik ve yedekleme sa\u011flar. MySQL'de **Master-Slave** \u00e7o\u011faltma yap\u0131s\u0131 yayg\u0131n olarak kullan\u0131l\u0131r.<\/p><p>#### Master-Slave \u00c7o\u011faltma Kurulumu<\/p><p>1. **Master Sunucu Yap\u0131land\u0131rmas\u0131:**<br>&nbsp; - Master sunucuda bir kullan\u0131c\u0131 olu\u015fturun ve \u00e7o\u011faltma izinleri verin:<br>&nbsp; &nbsp; ```sql<br>&nbsp; &nbsp; CREATE USER 'repl_user'@'%' IDENTIFIED BY 'password';<br>&nbsp; &nbsp; GRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'%';<br>&nbsp; &nbsp; FLUSH PRIVILEGES;<br>&nbsp; &nbsp; ```<br>&nbsp; - `my.cnf` dosyas\u0131na a\u015fa\u011f\u0131daki sat\u0131rlar\u0131 ekleyin:<br>&nbsp; &nbsp; ```ini<br>&nbsp; &nbsp; server-id = 1<br>&nbsp; &nbsp; log-bin = mysql-bin.log<br>&nbsp; &nbsp; binlog-do-db = your_database<br>&nbsp; &nbsp; ```<br>&nbsp; - MySQL sunucusunu yeniden ba\u015flat\u0131n.<\/p><p>2. **Slave Sunucu Yap\u0131land\u0131rmas\u0131:**<br>&nbsp; - `my.cnf` dosyas\u0131na a\u015fa\u011f\u0131daki sat\u0131rlar\u0131 ekleyin:<br>&nbsp; &nbsp; ```ini<br>&nbsp; &nbsp; server-id = 2<br>&nbsp; &nbsp; master-host = master_ip_address<br>&nbsp; &nbsp; master-user = repl_user<br>&nbsp; &nbsp; master-password = password<br>&nbsp; &nbsp; replicate-do-db = your_database<br>&nbsp; &nbsp; ```<br>&nbsp; - MySQL sunucusunu yeniden ba\u015flat\u0131n.<\/p><p>3. **Verileri Slave'e Kopyalama:**<br>&nbsp; - Master sunucuda verileri kilitleyin ve yedek al\u0131n:<br>&nbsp; &nbsp; ```sql<br>&nbsp; &nbsp; FLUSH TABLES WITH READ LOCK;<br>&nbsp; &nbsp; mysqldump your_database -u root -p &gt; backup.sql;<br>&nbsp; &nbsp; ```<br>&nbsp; - Yede\u011fi Slave sunucuya aktar\u0131n:<br>&nbsp; &nbsp; ```bash<br>&nbsp; &nbsp; mysql -u root -p your_database &lt; backup.sql<br>&nbsp; &nbsp; ```<\/p><p>4. **\u00c7o\u011faltmay\u0131 Ba\u015flatma:**<br>&nbsp; - Master sunucuda log dosyas\u0131 ve pozisyon bilgisini al\u0131n:<br>&nbsp; &nbsp; ```sql<br>&nbsp; &nbsp; SHOW MASTER STATUS;<br>&nbsp; &nbsp; ```<br>&nbsp; - Slave sunucuda \u00e7o\u011faltmay\u0131 ba\u015flat\u0131n:<br>&nbsp; &nbsp; ```sql<br>&nbsp; &nbsp; CHANGE MASTER TO MASTER_HOST='master_ip_address', MASTER_USER='repl_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=130;<br>&nbsp; &nbsp; START SLAVE;<br>&nbsp; &nbsp; ```<\/p><p>---<\/p><p>### \u00c7o\u011faltma Hatalar\u0131 ve \u00c7\u00f6z\u00fcmleri<\/p><p>\u00c7o\u011faltma s\u0131ras\u0131nda hatalar olu\u015fabilir. \u00d6rne\u011fin, bir sorgu Slave'de \u00e7al\u0131\u015ft\u0131r\u0131lamazsa \u00e7o\u011faltma durdurulabilir. Bu t\u00fcr hatalar\u0131 atlamak i\u00e7in a\u015fa\u011f\u0131daki komut kullan\u0131labilir:<\/p><p>```sql<br>STOP SLAVE;<br>SET GLOBAL sql_slave_skip_counter=1;<br>START SLAVE;<br>```<\/p><p>Ancak, bu t\u00fcr hatalar\u0131 atlamak veri tutars\u0131zl\u0131\u011f\u0131na neden olabilece\u011finden dikkatli olunmal\u0131d\u0131r.<\/p><p>---<\/p><p>### Sonu\u00e7<\/p><p>MySQL'de b\u00f6l\u00fcmleme ve \u00e7o\u011faltma, b\u00fcy\u00fck veri k\u00fcmelerini y\u00f6netmek ve y\u00fcksek kullan\u0131labilirlik sa\u011flamak i\u00e7in g\u00fc\u00e7l\u00fc ara\u00e7lard\u0131r. Do\u011fru yap\u0131land\u0131r\u0131ld\u0131\u011f\u0131nda, bu teknikler veritaban\u0131 performans\u0131n\u0131 \u00f6nemli \u00f6l\u00e7\u00fcde art\u0131rabilir ve veri g\u00fcvenli\u011fini sa\u011flayabilir. Bu y\u00f6ntemleri uygularken, veri tutarl\u0131l\u0131\u011f\u0131n\u0131 korumak ve olas\u0131 hatalar\u0131 dikkatlice y\u00f6netmek \u00f6nemlidir.<\/p>","excerpt":"MySQL'de b\u00f6l\u00fcmleme ve \u00e7o\u011faltma, b\u00fcy\u00fck veri k\u00fcmelerini y\u00f6netmek ve y\u00fcksek kullan\u0131labilirlik sa\u011flamak i\u00e7in g\u00fc\u00e7l\u00fc ara\u00e7lard\u0131r. Do\u011fru yap\u0131land\u0131r\u0131ld\u0131\u011f\u0131nda, bu teknikler veritaban\u0131 performans\u0131n\u0131 \u00f6nemli \u00f6l\u00e7\u00fcde art\u0131rabilir ve veri g\u00fcvenli\u011fini sa\u011flayabilir. Bu y\u00f6ntemleri uygularken, veri tutarl\u0131l\u0131\u011f\u0131n\u0131 korumak ve olas\u0131 hatalar\u0131 dikkatlice y\u00f6netmek \u00f6nemlidir.","created_at":"2025-01-13 15:48:26","updated_at":"2026-09-08 02:04:51","category_id":9,"view_count":541,"reading_time":5,"status":"published","editor_choice":0,"is_editor_choice":0,"published_at":"2025-01-13 15:48:26","featured_image":"resimyok.jpg","slug":"sql-notlari-partitioning-replication","category_name":"Yaz\u0131l\u0131m","category_slug":"yazilim","category_color":"#ef4444"}