Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial mysql 两个数据库中表的结构不同,怎么把一个表中的数据导入到另一个表中

mysql 两个数据库中表的结构不同,怎么把一个表中的数据导入到另一个表中

Jun 23, 2016 pm 02:23 PM

mysql 两个数据库中表的结构不同,怎么把一个表中的数据导入到另一个表中


回复讨论(解决方案)

表结构不一样 那就只能用php读取数据然后 insert 了.要不咋地?计算机能智能到跟你心灵相通嘛

将表A中的查出来经过php处理将指定的字段用自定义的东西填充或者取出多出的字段然后放入到B表中

怎么个不同法?
给出两表结构,并说明需要将哪个表的哪些字段导入到另一个表的哪些字段中去



这个是要导入表的结构
CREATE TABLE IF NOT EXISTS `job_hr` (
  `m_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `m_login` varchar(50) NOT NULL,
  `m_pwd` varchar(32) NOT NULL,
  `m_sendemail` tinyint(1) NOT NULL DEFAULT '0',
  `m_question` varchar(50) NOT NULL,
  `m_answer` varchar(50) NOT NULL,
  `m_typeid` tinyint(1) NOT NULL DEFAULT '0',
  `m_groupid` tinyint(2) NOT NULL DEFAULT '0',
  `m_email` varchar(100) NOT NULL,
  `m_email2` varchar(100) DEFAULT NULL COMMENT '备用邮箱(S+)',
  `m_emailshowflag` tinyint(1) NOT NULL DEFAULT '0',
  `m_name` varchar(200) NOT NULL,
  `m_sex` tinyint(1) NOT NULL DEFAULT '0',
  `m_birth` date NOT NULL DEFAULT '0000-00-00',
  `m_cardtype` tinyint(1) NOT NULL DEFAULT '0',
  `m_idcard` varchar(20) NOT NULL,
  `m_marriage` varchar(10) NOT NULL,
  `m_polity` varchar(10) NOT NULL,
  `m_hukou` varchar(100) NOT NULL,
  `m_seat` varchar(100) NOT NULL,
  `m_edu` tinyint(2) NOT NULL,
  `m_address` varchar(200) NOT NULL,
  `m_post` varchar(6) NOT NULL,
  `m_contact` varchar(50) NOT NULL,
  `m_chat` varchar(20) NOT NULL,
  `m_tel` varchar(100) NOT NULL,
  `m_telshowflag` tinyint(1) NOT NULL DEFAULT '0',
  `m_fax` varchar(50) NOT NULL,
  `m_url` varchar(100) NOT NULL,
  `m_regdate` int(11) NOT NULL,
  `m_logindate` int(11) NOT NULL,
  `m_loginip` varchar(15) NOT NULL DEFAULT '000.000.000.000',
  `m_loginnum` int(10) NOT NULL,
  `m_level` varchar(50) NOT NULL,
  `m_balance` int(10) NOT NULL DEFAULT '0',
  `m_integral` int(10) NOT NULL DEFAULT '0',
  `m_flag` tinyint(1) NOT NULL DEFAULT '0',
  `m_startdate` date NOT NULL DEFAULT '0000-00-00',
  `m_enddate` date NOT NULL DEFAULT '0000-00-00',
  `m_resumenums` mediumint(6) NOT NULL DEFAULT '0',
  `m_mysendnums` mediumint(6) NOT NULL DEFAULT '0',
  `m_myinterviewnums` mediumint(6) NOT NULL DEFAULT '0',
  `m_myfavoritenums` mediumint(6) NOT NULL DEFAULT '0',
  `m_letternums` tinyint(2) NOT NULL DEFAULT '0',
  `m_hirenums` mediumint(6) NOT NULL DEFAULT '0',
  `m_interviewnums` mediumint(6) NOT NULL DEFAULT '0',
  `m_expertnums` mediumint(6) NOT NULL DEFAULT '0',
  `m_comm` tinyint(1) NOT NULL DEFAULT '0',
  `m_commstart` date NOT NULL DEFAULT '0000-00-00',
  `m_commend` date NOT NULL DEFAULT '0000-00-00',
  `m_logo` varchar(50) NOT NULL,
  `m_logostatus` tinyint(1) NOT NULL DEFAULT '0',
  `m_logoflag` tinyint(1) NOT NULL DEFAULT '0',
  `m_logocomm` tinyint(1) NOT NULL DEFAULT '0',
  `m_logostartdate` date NOT NULL DEFAULT '0000-00-00',
  `m_logoenddate` date NOT NULL DEFAULT '0000-00-00',
  `m_licence` varchar(100) NOT NULL,
  `m_trade` varchar(50) NOT NULL,
  `m_tradeid` smallint(5) NOT NULL,
  `m_ecoclass` varchar(20) NOT NULL,
  `m_fund` mediumint(6) NOT NULL DEFAULT '0',
  `m_workers` varchar(10) NOT NULL,
  `m_founddate` date NOT NULL DEFAULT '0000-00-00',
  `m_introduce` mediumtext NOT NULL,
  `m_teachers` mediumtext NOT NULL,
  `m_achievement` mediumtext NOT NULL,
  `m_hits` int(10) NOT NULL DEFAULT '0',
  `m_template` varchar(20) NOT NULL,
  `m_activedate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `m_mobile` varchar(20) NOT NULL,
  `m_mobileshowflag` tinyint(1) NOT NULL DEFAULT '0',
  `m_smsnum` smallint(4) NOT NULL DEFAULT '0',
  `m_hirenum` smallint(4) NOT NULL DEFAULT '0',
  `m_myinterviewnum` smallint(4) NOT NULL DEFAULT '0',
  `m_expertnum` smallint(4) NOT NULL DEFAULT '0',
  `m_recyclenums` mediumint(6) NOT NULL DEFAULT '0',
  `m_recyclenum` smallint(4) NOT NULL DEFAULT '0',
  `m_contactnums` mediumint(6) NOT NULL DEFAULT '0',
  `m_contactnum` smallint(4) NOT NULL DEFAULT '0',
  `m_smsnums` mediumint(6) NOT NULL DEFAULT '0',
  `m_mysendnum` smallint(4) NOT NULL DEFAULT '0',
  `m_myfavoritenum` smallint(4) NOT NULL DEFAULT '0',
  `m_ishire` smallint(4) NOT NULL DEFAULT '0',
  `m_operator` varchar(20) NOT NULL,
  `m_map` varchar(50) NOT NULL,
  `m_confirm` tinyint(1) NOT NULL DEFAULT '0',
  
  PRIMARY KEY (`m_id`),
  KEY `m_regdate` (`m_regdate`),
  KEY `m_enddate` (`m_enddate`),
  KEY `m_logindate` (`m_logindate`),
  KEY `m_login` (`m_login`),
  KEY `m_activedate` (`m_activedate`),
  KEY `m_startdate` (`m_startdate`),
  KEY `m_ishire` (`m_ishire`),
  KEY `m_logoflag` (`m_logoflag`),
  KEY `m_logostatus` (`m_logostatus`)
) ENGINE=MyISAM  DEFAULT 

CHARSET=gbk AUTO_INCREMENT=122851 ;


这个是有数据的表
 create  table jobinfo(
  id int(11)              
  jname varchar(50)                
  jdesc text                 
  jexp varchar(20)            
  knw varchar(20)               
  mgexp varchar(30)               
  jattr varchar(10)               
  num varchar(10)               
  paymt varchar(10)             
  conn text            
  waddr varchar(100)             
  pdate varchar(20)            
  jtype varchar(20)            
  cid varchar(10)             
  url varchar(50)              
  compname varchar(50)               
  companyaddr varchar(1000)              
  mailbox varchar(1000)             
  cmsg varchar(1000)            
  linkman varchar(20)               
)

我去,这数据表,这么多个字段,你是把所有字段都放一个表了么?

只把下面的表的数据插入第一张表里

你没有给出把哪个字段放到哪个字段中去

例如 jobinfo表中的companyaddr 放入job_hr表中的 m_address 

例如 jobinfo表中的companyaddr 放入job_hr表中的 m_address
你已经完成大半了
例如
insert into job_hr (m_address) values select companyaddr from jobinfo

它们在两个不的数据库啊  有没有代码啊 这样一个个的添加很麻烦的  谢谢啦

本帖最后由 xuzuning 于 2011-08-26 06:50:08 编辑

insert into job_hr (库1.m_address) values select companyaddr from 库2.jobinfo

当然不能一个一个添加,就是加了,也是不对

insert into 库1.job_hr (字段列表) values select 对应的字段列表 from 库2.jobinfo

根据主健,联表更新

insert into job_hr (库1.m_address) values select companyaddr from 库2.jobinfo

当然不能一个一个添加,就是加了,也是不对

insert into 库1.job_hr (字段列表) values select 对应的字段列表 from 库2.jobinfo
 11# 真高手~ 那如果数据类型不一样 比如两个都是char呢 也能吗? 

我已经搞完了 谢谢各位高手帮忙

楼主,你是怎么搞定的?

怎么搞定的?现在急需,如果表中的数据很多,比如几百万条,怎么移

老老实实写程序导吧

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? Apr 01, 2025 pm 03:09 PM

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...

See all articles