分庫分表在小型公司很少能遇到也很少使用,畢竟數據量沒有那麼大,當數據量大,所有數據都壓在一張表時,如果單從數據庫的角度考慮是可以分庫分表處理來存儲數據。分庫分表 顧名思義就是根據查詢條件動態的去獲取數據所在的庫和表的位置.例如一個系統有唯一的標識userNum,所有路由規則都可以根據userNum做庫表的定位工作.本文測試用3個庫5個表做測試.
三個庫book_00,book_01,book_02 每個庫裏的表 t_user_0000,t_user_0001,t_user_0002,t_user_0003,t_user_0004,
根據userNum尋找匹配庫的_00後綴,匹配表的_0000 後綴 即可定位到是幾庫幾表.
本人會建立一個新的項目,一步一步講解如果簡單的搭建一個分庫分表的系統並且用頁面展示從庫裏查詢出來的數據.
1,首先需要創建一個新的maven的webApp項目
![](http://static.javashuo.com/static/loading.gif)
使用框架版本:
Spring 4.0.2 RELEASE
Spring MVC 4.0.2 RELEASE
MyBatis 3.2.6
2,pom裏引入jar包
首先看下目錄結構
3,Spring與MyBatis的整合
首先創建 jdbc.properties 配置數據庫信息
- driver=com.mysql.jdbc.Driver
- #定義初始連接數
- initialSize=0
- #定義最大連接數
- maxActive=20
- #定義最大空閒
- maxIdle=20
- #定義最小空閒
- minIdle=1
- #定義最長等待時間
- maxWait=60000
-
- jdbc.mysql.url0=jdbc:mysql://localhost:3306/book_02?createDatabaseIfNotExist=true&characterEncoding=utf-8&useUnicode=true
- jdbc.mysql.username0=root
- jdbc.mysql.password0=123456
-
- jdbc.mysql.url1=jdbc:mysql://localhost:3306/book_00?createDatabaseIfNotExist=true&characterEncoding=utf-8&useUnicode=true
- jdbc.mysql.username1=root
- jdbc.mysql.password1=123456
-
- jdbc.mysql.url2=jdbc:mysql://localhost:3306/book_01?createDatabaseIfNotExist=true&characterEncoding=utf-8&useUnicode=true
- jdbc.mysql.username2=root
- jdbc.mysql.password2=123456
創建Spring配置文件 spring-config.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
- default-autowire="byName">
- <context:component-scan base-package="com.sub.dt"/>
- <aop:aspectj-autoproxy/>
- <!-- 屬性文件讀入 -->
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <list>
- <value>classpath:props/*.properties</value>
- </list>
- </property>
- </bean>
-
- <import resource="classpath:spring/spring-*.xml"/>
-
- </beans>
創建spring與mybatis結合的整合配置文件. spring-config-datasource-dbcp.xml
這個文件主要是多數據源配置,自動掃描mybatis的xml配置文件.
程序使用spring aop切面+自定義註解的方式去在每個方法調用時根據userNum定位庫表, 關鍵類已標紅(代碼會上傳附件自行下載查看)
![](http://static.javashuo.com/static/loading.gif)
spring-config-datasource-dbcp.xml中配置的com.sub.dt.dbRouting.db.DynamicDataSource 繼承 AbstractRoutingDataSource方法,單表配置mybatis是使用的是BasicDataSource
BasicDataSourBasicDataSource
BasicDataSource 自定義的AbstractRoutingDataSource與spring的BasicDataSource都是一個道理 管理數據源 實現了DataSource接口.
- package com.sub.dt.dbRouting.db;
-
-
- import com.sub.dt.dbRouting.DbContextHolder;
- import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
-
- import java.util.logging.Logger;
-
- /**
- * @Description SPring 的動態數據源的實現
- * @Autohr supers【weChat:13031016567】
- */
- public class DynamicDataSource extends AbstractRoutingDataSource {
- public static final Logger logger = Logger.getLogger(DynamicDataSource.class.toString());
- @Override
- protected Object determineCurrentLookupKey() {
- return DbContextHolder.getDbKey();//獲取當前數據源
- }
-
- }
UserMapper.xml創建庫表對應的xml文件
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
- <mapper namespace="com.sub.dt.dao.IUserDao">
- <resultMap id="BaseResultMap" type="com.sub.dt.pojo.User">
- <id column="id" property="id" jdbcType="INTEGER"/>
- <result column="user_name" property="userName" jdbcType="VARCHAR"/>
- <result column="password" property="password" jdbcType="VARCHAR"/>
- <result column="age" property="age" jdbcType="INTEGER"/>
- <result column="user_num" property="userNum" jdbcType="VARCHAR"/>
- </resultMap>
- <sql id="Base_Column_List">
- id,user_num, user_name, password, age
- </sql>
-
- <insert id="insertUser" parameterType="com.sub.dt.pojo.User">
- insert into t_user${tableIndex} (id,user_num,user_name, password,age)
- values (#{id,jdbcType=INTEGER},#{userNum,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},#{age,jdbcType=INTEGER})
- </insert>
-
-
- <insert id="deleteByuserNum" parameterType="com.sub.dt.pojo.User">
- delete from t_user${tableIndex}
- where user_num = #{userNum,jdbcType=VARCHAR}
- </insert>
-
- <update id="updateByUserNum" parameterType="com.sub.dt.pojo.User">
- update t_user${tableIndex}
- <set>
- <if test="userName != null">
- user_name = #{userName,jdbcType=VARCHAR},
- </if>
- <if test="password != null">
- password = #{password,jdbcType=VARCHAR},
- </if>
- <if test="age != null">
- age = #{age,jdbcType=INTEGER},
- </if>
- </set>
- where user_num = #{userNum,jdbcType=VARCHAR}
- </update>
-
- <select id="selectByUserNum" resultMap="BaseResultMap" parameterType="com.sub.dt.pojo.User">
- select
- <include refid="Base_Column_List"/>
- from t_user${tableIndex}
- where user_num = #{userNum,jdbcType=VARCHAR}
- </select>
- </mapper>
IUserDao.java
- package com.sub.dt.dao;
-
- import com.sub.dt.pojo.User;
-
- public interface IUserDao {
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- int insertUser(User user);
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- int deleteByuserNum(User user);
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- int updateByUserNum(User user);
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- User selectByUserNum(User user);
- }
IUserService.java
- package com.sub.dt.service;
-
- import com.sub.dt.pojo.User;
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- public interface IUserService {
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- public int insertUser(User user);
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- public int deleteByuserNum(User user);
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- public int updateByUserNum(User user);
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- public User selectByUserNum(User user);
-
-
- }
UserServiceImpl.java
- package com.sub.dt.service.impl;
-
- import com.sub.dt.dao.IUserDao;
- import com.sub.dt.dbRouting.annotation.Router;
- import com.sub.dt.pojo.User;
- import com.sub.dt.service.IUserService;
- import org.springframework.stereotype.Service;
-
- import javax.annotation.Resource;
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- @Service("userService")
- public class UserServiceImpl implements IUserService {
-
- @Resource
- private IUserDao userDao;
-
- @Router
- public int insertUser(User user) {
- return this.userDao.insertUser(user);
- }
-
- @Router
- public int deleteByuserNum(User user) {
- return this.userDao.deleteByuserNum(user);
- }
-
- @Router
- public int updateByUserNum(User user) {
- return this.userDao.updateByUserNum(user);
- }
-
- @Router
- public User selectByUserNum(User user) {
- return this.userDao.selectByUserNum(user);
- }
- }
UserController.java
- package com.sub.dt.controller;
-
- import com.sub.dt.pojo.User;
- import com.sub.dt.service.IUserService;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
-
- @Controller
- @RequestMapping("/user")
- public class UserController {
- @Resource
- private IUserService userService;
-
- @RequestMapping("/queryUser")
- public String toIndex(HttpServletRequest request,Model model,User user){
- User userDb = this.userService.selectByUserNum(user);
- model.addAttribute("user", userDb);
- return "queryUser";
- }
- }
4,核心分庫分表包都在dbRouting文件夾下
Router.java 自定義註解,此註解作用是當做一個切點,在方法上添加此註解,執行方法前會執行DBRouterInterceptor的doRoute方法.詳情可參考:http://blog.csdn.net/buchengbugui/article/details/60875401
- package com.sub.dt.dbRouting.annotation;
-
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
-
- /**
- * @Description
- * @Autohr supers【weChat:13031016567】
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.METHOD)
- public @interface Router {
-
- String routerField() default RouterConstants.ROUTER_FIELD_DEFAULT;
-
- String tableStyle() default RouterConstants.ROUTER_TABLE_SUFFIX_DEFAULT;
- }
DBRouterInterceptor.java 定義切點爲方法上使用,@Router註解的方法,執行註解方法前前執行doRoute方法,根據參數中的userNum設置是幾庫幾表
- package com.sub.dt.dbRouting;
-
- import com.sub.dt.dbRouting.annotation.Router;
- import com.sub.dt.dbRouting.annotation.RouterConstants;
- import com.sub.dt.dbRouting.router.RouterUtils;
- import org.apache.commons.beanutils.BeanUtils;
- import org.apache.commons.lang.StringUtils;
- import org.aspectj.lang.JoinPoint;
- import org.aspectj.lang.Signature;
- import org.aspectj.lang.annotation.Aspect;
- import org.aspectj.lang.annotation.Before;
- import org.aspectj.lang.annotation.Pointcut;
- import org.aspectj.lang.reflect.MethodSignature;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
-
- import java.lang.reflect.Method;
-
- /**
- * @Description 切面切點 在Router註解的方法執行前執行 切點織入
- * @Autohr supers【weChat:13031016567】
- */
- @Aspect
- @Component
- public class DBRouterInterceptor {
-
- private static final Logger log = LoggerFactory.getLogger(DBRouterInterceptor.class);
-
- private DBRouter dBRouter;
-
- @Pointcut("@annotation( com.sub.dt.dbRouting.annotation.Router)")
- public void aopPoint() {
- }
-
- @Before("aopPoint()")
- public Object doRoute(JoinPoint jp) throws Throwable {
- long t1 = System.currentTimeMillis();
- boolean result = true;
- Method method = getMethod(jp);
- Router router = method.getAnnotation(Router.class);
- String routeField = router.routerField();
- Object[] args = jp.getArgs();
- if (args != null && args.length > 0) {
- for (int i = 0; i < args.length; i++) {
- long t2 = System.currentTimeMillis();
- String routeFieldValue = BeanUtils.getProperty(args[i],
- routeField);
- log.debug("routeFieldValue{}" + (System.currentTimeMillis() - t2));
- if (StringUtils.isNotEmpty(routeFieldValue)) {
- if (RouterConstants.ROUTER_FIELD_DEFAULT.equals(routeField)) {
- dBRouter.doRouteByResource("" + RouterUtils.getResourceCode(routeFieldValue));
- break;
- } else {
- this.searchParamCheck(routeFieldValue);
- String resource = routeFieldValue.substring(routeFieldValue.length() - 4);
- dBRouter.doRouteByResource(resource);
- break;
- }
- }
- }
- }
- log.debug("doRouteTime{}" + (System.currentTimeMillis() - t1));
- return result;
- }
-
- private Method getMethod(JoinPoint jp) throws NoSuchMethodException {
- Signature sig = jp.getSignature();
- MethodSignature msig = (MethodSignature) sig;
- return getClass(jp).getMethod(msig.getName(), msig.getParameterTypes());
- }
-
- private Class<? extends Object> getClass(JoinPoint jp)
- throws NoSuchMethodException {
- return jp.getTarget().getClass();
- }
-
-
- /**
- * 查詢支付結構參數檢查
- *
- * @param payId
- */
- private void searchParamCheck(String payId) {
- if (payId.trim().equals("")) {
- throw new IllegalArgumentException("payId is empty");
- }
- }
-
- public DBRouter getdBRouter() {
- return dBRouter;
- }
-
- public void setdBRouter(DBRouter dBRouter) {
- this.dBRouter = dBRouter;
- }
-
- }
RouterSet.java 主要是 配置在spring-config-datasource-dbcp.xml中 存儲庫的數量,表的數量,庫表相關信息
DBRouterImpl.java getDbKey方法根據userNum定位庫表算法
- package com.sub.dt.dbRouting.router;
-
- import com.sub.dt.dbRouting.DBRouter;
- import com.sub.dt.dbRouting.DbContextHolder;
- import com.sub.dt.dbRouting.annotation.RouterConstants;
- import com.sub.dt.dbRouting.bean.RouterSet;
- import org.apache.commons.lang.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
-
- import java.text.DecimalFormat;
- import java.util.List;
-
- /**
- * @Description 根據指定變量動態切 庫和表
- * @Autohr supers【weChat:13031016567】
- */
- public class DBRouterImpl implements DBRouter {
-
- private static final Logger log = LoggerFactory.getLogger(DBRouterImpl.class);
-
- /**
- * 配置列表
- */
- private List<RouterSet> routerSetList;
-
- @Override
- public String doRoute(String fieldId) {
- if (StringUtils.isEmpty(fieldId)) {
- throw new IllegalArgumentException("dbsCount and tablesCount must be both positive!");
- }
- int routeFieldInt = RouterUtils.getResourceCode(fieldId);
- String dbKey = getDbKey(routerSetList, routeFieldInt);
- return dbKey;
- }
-
- @Override
- public String doRouteByResource(String resourceCode) {
- if (StringUtils.isEmpty(resourceCode)) {
- throw new IllegalArgumentException("dbsCount and tablesCount must be both positive!");
- }
- int routeFieldInt = Integer.valueOf(resourceCode);
- String dbKey = getDbKey(routerSetList, routeFieldInt);
- return dbKey;
- }
-
-
- /**
- * @Description 根據數據字段來判斷屬於哪個段的規則,獲得數據庫key
- * @Autohr supers【weChat:13031016567】
- */
- private String getDbKey(List<RouterSet> routerSets, int routeFieldInt) {
- RouterSet routerSet = null;
- if (routerSets == null || routerSets.size() <= 0) {
- throw new IllegalArgumentException("dbsCount and tablesCount must be both positive!");
- }
- String dbKey = null;
- for (RouterSet item : routerSets) {
- if (item.getRuleType() == routerSet.RULE_TYPE_STR) {
- routerSet = item;
- if (routerSet.getDbKeyArray() != null && routerSet.getDbNumber() != 0) {
- long dbIndex = 0;
- long tbIndex = 0;
- //默認按照分庫進行計算
- long mode = routerSet.getDbNumber();
- //如果是按照分庫分表的話,計算
- if (item.getRouteType() == RouterSet.ROUTER_TYPE_DBANDTABLE && item.getTableNumber() != 0) {
- mode = routerSet.getDbNumber() * item.getTableNumber();
- dbIndex = routeFieldInt % mode / item.getTableNumber();
- tbIndex = routeFieldInt % item.getTableNumber();
- String tableIndex = getFormateTableIndex(item.getTableIndexStyle(), tbIndex);
- DbContextHolder.setTableIndex(tableIndex);
- } else if (item.getRouteType() == RouterSet.ROUTER_TYPE_DB) {
- mode = routerSet.getDbNumber();
- dbIndex = routeFieldInt % mode;
- } else if (item.getRouteType() == RouterSet.ROUTER_TYPE_TABLE) {
- tbIndex = routeFieldInt % item.getTableNumber();
- String tableIndex = getFormateTableIndex(item.getTableIndexStyle(), tbIndex);
- DbContextHolder.setTableIndex(tableIndex);
- }
- dbKey = routerSet.getDbKeyArray().get(Long.valueOf(dbIndex).intValue());
- log.debug("getDbKey resource:{}------->dbkey:{},tableIndex:{},", new Object[]{routeFieldInt, dbKey, tbIndex});
- DbContextHolder.setDbKey(dbKey);
- }
- break;
- }
- }
- return dbKey;
- }
-
-
- /**
- * @Description 此方法是將例如+++0000根式的字符串替換成傳參數字例如44 變成+++0044
- * @Autohr supers【weChat:13031016567】
- */
- private static String getFormateTableIndex(String style, long tbIndex) {
- String tableIndex = null;
- DecimalFormat df = new DecimalFormat();
- if (StringUtils.isEmpty(style)) {
- style = RouterConstants.ROUTER_TABLE_SUFFIX_DEFAULT;//在格式後添加諸如單位等字符
- }
- df.applyPattern(style);
- tableIndex = df.format(tbIndex);
- return tableIndex;
- }
-
- public List<RouterSet> getRouterSetList() {
- return routerSetList;
- }
-
- public void setRouterSetList(List<RouterSet> routerSetList) {
- this.routerSetList = routerSetList;
- }
- }
spring-mvc.xml這個很簡單了 就是前段與後端controller層的結合,不多說.
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd">
- <!-- 自動掃描該包,使SpringMVC認爲包下用了@controller註解的類是控制器 -->
- <context:component-scan base-package="com.sub.dt.controller"/>
- <!--避免IE執行AJAX時,返回JSON出現下載文件 -->
- <bean id="mappingJacksonHttpMessageConverter"
- class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
- <property name="supportedMediaTypes">
- <list>
- <value>text/html;charset=UTF-8</value>
- </list>
- </property>
- </bean>
- <!-- 啓動SpringMVC的註解功能,完成請求和註解POJO的映射 -->
- <bean
- class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
- <property name="messageConverters">
- <list>
- <ref bean="mappingJacksonHttpMessageConverter"/>
- <!-- JSON轉換器 -->
- </list>
- </property>
- </bean>
- <!-- 定義跳轉的文件的前後綴 ,視圖模式配置-->
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <!-- 這裏的配置我的理解是自動給後面action的方法return的字符串加上前綴和後綴,變成一個 可用的url地址 -->
- <property name="prefix" value="/WEB-INF/jsp/"/>
- <property name="suffix" value=".jsp"/>
- </bean>
-
- <!-- 配置文件上傳,如果沒有使用文件上傳可以不用配置,當然如果不配,那麼配置文件中也不必引入上傳組件包 -->
- <bean id="multipartResolver"
- class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
- <!-- 默認編碼 -->
- <property name="defaultEncoding" value="utf-8"/>
- <!-- 文件大小最大值 -->
- <property name="maxUploadSize" value="10485760000"/>
- <!-- 內存中的最大值 -->
- <property name="maxInMemorySize" value="40960"/>
- </bean>
-
- </beans>
web.xml配置
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
- <display-name>Archetype Created Web Application</display-name>
- <!-- Spring和mybatis的配置文件 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:spring-config.xml</param-value>
- </context-param>
- <!-- 編碼過濾器 -->
- <filter>
- <filter-name>encodingFilter</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <async-supported>true</async-supported>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>encodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!-- Spring監聽器 -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- 防止Spring內存溢出監聽器 -->
- <listener>
- <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
- </listener>
-
- <!-- Spring MVC servlet -->
- <servlet>
- <servlet-name>SpringMVC</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:spring-mvc.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- <async-supported>true</async-supported>
- </servlet>
- <servlet-mapping>
- <servlet-name>SpringMVC</servlet-name>
- <!-- 此處可以可以配置成*.do,對應struts的後綴習慣 -->
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>/index.jsp</welcome-file>
- </welcome-file-list>
-
- </web-app>
奉上 mysql創建表的sql語句,首先自行創建三個庫book_00,book_01,book_02 每個庫都執行以下sql即可
- /*
- Navicat MySQL Data Transfer
-
- Source Server : local
- Source Server Version : 50173
- Source Host : localhost:3306
- Source Database : book_00
-
- Target Server Type : MYSQL
- Target Server Version : 50173
- File Encoding : 65001
-
- Date: 2017-03-10 09:48:12
- */
-
- SET FOREIGN_KEY_CHECKS=0;
-
- -- ----------------------------
- -- Table structure for `t_user_0000`
- -- ----------------------------
- DROP TABLE IF EXISTS `t_user_0000`;
- CREATE TABLE `t_user_0000` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `user_num` varchar(64) NOT NULL,
- `user_name` varchar(16) NOT NULL,
- `password` varchar(64) NOT NULL,
- `age` int(4) NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `idx_user_num` (`user_num`)
- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-
- -- ----------------------------
- -- Records of t_user_0000
- -- ----------------------------
-
- -- ----------------------------
- -- Table structure for `t_user_0001`
- -- ----------------------------
- DROP TABLE IF EXISTS `t_user_0001`;
- CREATE TABLE `t_user_0001` (
- `id` int(11) NOT