473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

insert MySQL table data into a new table of a new database

76
Hi,
Is there any way I could insert the data from my current database table to a new table in a new database easily without the need to insert them one-by-one?
I'd appreciate it.
Nov 20 '07 #1
3 1662
bartonc
6,596 Expert 4TB
Hi,
Is there any way I could insert the data from my current database table to a new table in a new database easily without the need to insert them one-by-one?
I'd appreciate it.
To copy a table for the current (default) database:
Expand|Select|Wrap|Line Numbers
  1. DROP DATABASE IF EXISTS dbName;
  2. CREATE DATABASE dbName;
  3. CREATE TABLE dbName.tableName LIKE tableName;
  4. INSERT INTO dbName.tableName SELECT * FROM tableName;
Nov 20 '07 #2
mwasif
802 Expert 512MB
To copy a table for the current (default) database:
Expand|Select|Wrap|Line Numbers
  1. DROP DATABASE IF EXISTS dbName;
  2. CREATE DATABASE dbName;
  3. CREATE TABLE dbName.tableName LIKE tableName;
  4. INSERT INTO dbName.tableName SELECT * FROM tableName;
These commands will DROP the database dbName and create a empty database with the same name. If you already have the database, then you don't need to execute these commands.
Expand|Select|Wrap|Line Numbers
  1. DROP DATABASE IF EXISTS dbName;
  2. CREATE DATABASE dbName;
  3.  
The following command will select the data from old database and insert into the new one.
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO dbName.tableName SELECT * FROM tableName;
  2.  
If you have not created the destination (new database), then simply use bartonc's commands.
Nov 20 '07 #3
idorjee
76
thanks so much for both of you.
Nov 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
2
by: Tavish Muldoon | last post by:
What a pain trying to insert data into a table from a stored proc. My webform asks for 16 pieces of data - which then gets written to the database. I found this easier than the crap below...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
2
by: bballr | last post by:
I have a problem that I'm not sure if it can be done. I'm trying to use the MySQL C API to be able to use a normal sql insert statement that will send the data or file to a directory and NOT the...
9
by: David Eades | last post by:
Hi all Complete newbie here, so apologies if this is the wrong forum. I've been asked to use mysql and asp to make a simple bidding system (rather like a simple ebay), whereby users can use a...
14
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
1
by: erikcw | last post by:
Hi, I'm trying to insert some data from an XML file into MySQL. However, while importing one of the files, I got this error: Traceback (most recent call last): File "wa.py", line 304, in ?...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
7
by: dongletran06 | last post by:
Hi, Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input...
2
by: Deccypher | last post by:
sorry all i ever seam to do here is ask questions:( but im really stuck on the best way to do this what i have is 2 tables and im trying to make a 3rd table for compatibility example table...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.