---
title: "mysql分表算法 "
author: "zhb8015"
date: "2015-08-04T15:59:00Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2015-08-04T15:59:00Z"
id: 2232762
url: "https://peter8015.iteye.com/blog/2232762"
---

1\. 取模  uid % 20 + 1。（分20张表）

2\. hash

function get\_hash($id){  
       $str = bin2hex($id);  
       $hash = substr($str, 0, 4);  
       if (strlen($hash)&lt;4){  
           $hash = str\_pad($hash, 4, "0");  
       }  
       return $hash;  
}

3\. md5(uid)

4.按时间段