MySQL Table migration

Source: Internet
Author: User

http://blog.csdn.net/evan_endian/article/details/8652528

Bulk import of data from one table to another in  mysql   whether in web development or application development, we often encounter situations where you need to bulk import data from a table of MySQL or MS SQL Server into another table. Even sometimes you need to specify an import field.   This article will take the MySQL database as an example, how to import all the data of a table or the data of a specified field into the target table by SQL command line. This method is also true for SQL Server databases, which are T-SQL.   Category I, if the fields of two tables (export table and target table) are consistent, and you want to insert all the data, you can use this method: (This method is only suitable for exporting two tables in the same database)  insert into target table SELECT * from source table; To insert the articles table into the Newarticles table, you can do so by using the following SQL statement:  insert into Newarticles SELECT * from articles; category II, if you want to import only the specified fields, you can use this Way:  insert into target table (field 1, Field 2, ...) SELECT Field 1, Field 2, ... From source table; Note that the fields of both tables must be the same (field type), or a data conversion error will occur.  1, cross-server replication table data INSERT INTO OPENROWSET (' SQLOLEDB ', ' localhost '; ' Sa '; ' 123 ', Test.dbo.Table_B)  select * from test.dbo.table_a  //enable ad Hoc distributed Queries: exec sp_ Configure ' Show advanced options ', 1reconfigureexec sp_configure ' Ad Hoc distributed Queries ', 1reconfigure  / /after use is complete, close ad hoc distributed queries:exec sp_configure ' ad hoc distributed Queries ', 0reconfigureexec sp_configure ' show Ad vanced options ', 0 reconFigure
2,//Do not boast server insert INTO dbo. Table_b) SELECT * FROM dbo. Table_a the table name and database connection string in code, and then execute the SQL statement program function you need to complete.
How to import one table from a MySQL database into another MySQL database
DB1 is the original database, DB2 is the database to export to, fromtable is the table name to export 1. Method One:  log in the exported database, execute  CREATE TABLE fromtable select * FROM db1.fromtable ; 2. Method Two:  execute under CMD, mysqldump-u root-p db1 fromtable file=d:/fromtable.sql; Enter the secret, root login for user name  DB2 execute source d:/ Fromtable.sql;3. Method Three:  login DB1 Execute SELECT * from fromtable to outfile "d:/fromtable. txt"; Export pure Data Format  login DB2 execute load   Data   infile   d:/fromtable   . txt   into table fromtable; a blank table with the same structure as the original table needs to be built first. 4. Build an ODBC connection, export it to access first, and then export it to another library.

MySQL Table migration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.