NetAdminTools.com
 
SignalQ Sites:
L1G3R Information Systems - Coprolite - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - FixRambler
Solar Energy - Energy Efficiency - Solar Panels
Home Energy Savings
Categories:
GNU/Linux | Homebrew designs | Perl | Ruby | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | ERP | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Ruby
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·ERP
·REALbasic
·All Categories


Copying Table Structures With MySQL
Topic:Database   Date: 2003-06-24
Printer Friendly: Print   

spacerspacer
<<  <   >  >>

Subject

We often have to get basic tables in place for our MySQL web backend. To create a new database:

[root@main gg]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8374 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database data2;
Query OK, 1 row affected (0.01 sec)
mysql>

OK. We have a new database. Now, we want to clone a table from another database, so let's connect to it and list the structure:

mysql> connect data1
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Connection id:    8394
Current database: data1
mysql> show create table table1;
.
.
.
| table1 | CREATE TABLE `table1` (
`field1` int(11) NOT NULL auto_increment,
`field2` text NOT NULL,
`field3` text NOT NULL,
PRIMARY KEY  (`field1`)
) TYPE=MyISAM |
.
.
.
1 row in set (0.00 sec)
mysql>

Now, all we have to do is connect to the other database and paste the above as a command:

mysql> connect data2
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Connection id:    8395
Current database: data2
mysql> CREATE TABLE `table1` (
->   `field1` int(11) NOT NULL auto_increment,
->   `field2` text NOT NULL,
->   `field3` text NOT NULL,
->   PRIMARY KEY  (`field1`)
-> ) TYPE=MyISAM;
Query OK, 0 rows affected (0.00 sec)
mysql> 

We have now created a new database, and cloned table1.


People:
Places:
Things:
Times:





Please read our Terms of Use and our Privacy Policy
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2011 NetAdminTools.com