MySQL-克隆表

MySQL-克隆表 (MySQL - Clone Tables)

There may be a situation when you need an exact copy of a table and CREATE TABLE ... SELECT doesn't suit your purposes because the copy must include the same indexes, default values and so forth.

在某些情况下,您需要精确的表副本和CREATE TABLE ... SELECT不适合您的目的,因为该副本必须包含相同的索引,默认值等。

You can handle this situation by following the steps given below −

您可以按照以下步骤处理这种情况-

  • Use SHOW CREATE TABLE to get a CREATE TABLE statement that specifies the source table's structure, indexes and all.

    使用SHOW CREATE TABLE获得一个CREATE TABLE语句,该语句指定源表的结构,索引和所有内容。

  • Modify the statement to change the table name to that of the clone table and execute the statement. This way, you will have the exact clone table.

    修改该语句以将表名更改为克隆表的名称,然后执行该语句。 这样,您将拥有确切的克隆表。

  • Optionally, if you need the table contents copied as well, issue an INSERT INTO ... SELECT statement, too.

    可选地,如果您还需要复制表内容,也可以发出INSERT INTO ... SELECT语句。

(Example)

Try out the following example to create a clone table for tutorials_tbl.

试用以下示例为tutorials_tbl创建一个克隆表。

Step 1 − Get the complete structure about the table.

步骤1-获取有关表的完整结构。


mysql> SHOW CREATE TABLE tutorials_tbl \G;
*************************** 1. row ***************************
      Table: tutorials_tbl
Create Table: CREATE TABLE `tutorials_tbl` (
   `tutorial_id` int(11) NOT NULL auto_increment,
   `tutorial_title` varchar(100) NOT NULL default '',
   `tutorial_author` varchar(40) NOT NULL default '',
   `submission_date` date default NULL,
   PRIMARY KEY  (`tutorial_id`),
   UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`)
) TYPE = MyISAM
1 row in set (0.00 sec)

ERROR:
No query specified

Step 2 − Rename this table and create another table.

步骤2-重命名该表并创建另一个表。


mysql> CREATE TABLE clone_tbl (
   -> tutorial_id int(11) NOT NULL auto_increment,
   -> tutorial_title varchar(100) NOT NULL default '',
   -> tutorial_author varchar(40) NOT NULL default '',
   -> submission_date date default NULL,
   -> PRIMARY KEY  (tutorial_id),
   -> UNIQUE KEY AUTHOR_INDEX (tutorial_author)
-> ) TYPE = MyISAM;
Query OK, 0 rows affected (1.80 sec)

Step 3 − After executing step 2, you will create a clone table in your database. If you want to copy data from old table then you can do it by using INSERT INTO... SELECT statement.

步骤3-执行步骤2之后,您将在数据库中创建一个克隆表。 如果要从旧表中复制数据,则可以使用INSERT INTO ... SELECT语句来完成。


mysql> INSERT INTO clone_tbl (tutorial_id,
   -> tutorial_title,
   -> tutorial_author,
   -> submission_date)
   
   -> SELECT tutorial_id,tutorial_title,
   -> tutorial_author,submission_date
   -> FROM tutorials_tbl;
Query OK, 3 rows affected (0.07 sec)
Records: 3  Duplicates: 0  Warnings: 0

Finally, you will have an exact clone table as you wanted to have.

最后,您将拥有一个想要的精确克隆表。

翻译自: https://www.tutorialspoint.com/mysql/mysql-clone-tables.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL-tpcc是一个用于测试MySQL数据库性能的工具,可以模拟多个用户执行不同的事务负载。以下是配置MySQL-tpcc自动化测试的步骤: 1. 下载和安装MySQL-tpcc工具 MySQL-tpcc可以从GitHub上克隆,使用如下命令: ``` git clone https://github.com/Percona-Lab/tpcc-mysql.git ``` 在克隆完成后,可以进入到tpcc-mysql目录中,使用make命令编译。 2. 准备测试数据 使用tpcc_load工具,生成测试数据。tpcc_load可以使用如下命令: ``` ./tpcc_load -h host -P port -d dbname -u username -p password -w warehouse_count ``` 其中,host是MySQL服务器的主机名或IP地址,port是MySQL服务器的端口号,dbname是数据库名称,username是MySQL的用户名,password是MySQL的密码,warehouse_count是要生成的仓库数量。 3. 运行测试 使用tpcc_start工具,运行测试。tpcc_start可以使用如下命令: ``` ./tpcc_start -h host -P port -d dbname -u username -p password -w warehouse_count -c connection_count -r rampup_time -l running_time -f result_file -s scale_factor ``` 其中,host、port、dbname、username、password、warehouse_count与tpcc_load相同。connection_count是并发连接数,rampup_time是预热时间,running_time是运行时间,result_file是测试结果保存的文件,scale_factor是测试规模因子。 4. 结果分析 测试运行完成后,可以分析结果。MySQL-tpcc工具提供了一些脚本,可以对结果进行分析和图形化展示。其中,analyze.sh脚本可以分析结果,report.py脚本可以生成图。 例如,可以使用如下命令分析结果: ``` ./analyze.sh -f result_file -d dbname ``` 可以使用如下命令生成图: ``` python report.py result_file ``` 以上就是配置MySQL-tpcc自动化测试的步骤。可以使用脚本和工具将测试自动化,以便更好地进行性能测试和分析。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值