• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to copy existing table in mysql

November 12, 2013 by Sharad Chhetri Leave a Comment

In this post we will learn about how to copy the existing table in mysql. The newly copied table does not have data means it will be blank but it has similar rows information from its parent table.
After copying the table you have to insert the data by using INSERT command.

Follow the given below steps

Step (1): Login into mysql server. Replace the username with MySQL user name which you have.It will prompt you for password.

mysql -u username -p 

Step (2): Now connect with database.Replace database_name with your database.(show databases ; command will help you to list databases in MySQL server)

mysql > use database_name ;

Step 3: Now list the tables which you want to copy into new table. ( show tables ; command will help you to list tables).
Now copy the table

Original table name = table_name
New table name = table_name_NEW

mysql > create table table_name_NEW like table_name ;

Below given is reference of my MySQL server. Take it as an example.

mysql> use phpdirector;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_phpdirector |
+-----------------------+
| pp_categories         |
| pp_config             |
| pp_files              |
| pp_rating             |
+-----------------------+
4 rows in set (0.00 sec)

mysql> desc pp_config;
+---------------+--------------+------+-----+---------------+-------+
| Field         | Type         | Null | Key | Default       | Extra |
+---------------+--------------+------+-----+---------------+-------+
| name          | varchar(225) | YES  |     | NULL          |       |
| news          | varchar(225) | NO   |     | Welcome!      |       |
| vids_per_page | int(4)       | NO   |     | 10            |       |
| lang          | varchar(225) | NO   |     | en-gb.inc.php |       |
| version       | double       | NO   |     | NULL          |       |
| template      | varchar(255) | NO   |     | Photine       |       |
+---------------+--------------+------+-----+---------------+-------+
6 rows in set (0.00 sec)

mysql> create table pp_config_new like pp_config;
Query OK, 0 rows affected (0.16 sec)

mysql> desc pp_config_new;
+---------------+--------------+------+-----+---------------+-------+
| Field         | Type         | Null | Key | Default       | Extra |
+---------------+--------------+------+-----+---------------+-------+
| name          | varchar(225) | YES  |     | NULL          |       |
| news          | varchar(225) | NO   |     | Welcome!      |       |
| vids_per_page | int(4)       | NO   |     | 10            |       |
| lang          | varchar(225) | NO   |     | en-gb.inc.php |       |
| version       | double       | NO   |     | NULL          |       |
| template      | varchar(255) | NO   |     | Photine       |       |
+---------------+--------------+------+-----+---------------+-------+
6 rows in set (0.00 sec)

mysql> 

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. mysqldump: Got error: 145: Table ‘./DB/table-name’ is marked as crashed
  2. How to rename table in mysql using command line
  3. How to know storage engine of mysql table
  4. Attach security groups to existing instance with AWS cli
  5. Find mysql commands history without mysql server login
  6. How to install mysql server in RedHat and CentOS
  7. How to check default storage engine in MySQL server
  8. Install MySQL workbench in Ubuntu
  9. Change mysql default port number in linux
  10. How to create multiple mysql instance in CentOS 6.4 and Red Hat 6.4

Filed Under: mysql Tagged With: mysql

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

4 Different commands to find system uptime in linux

New XAMPP security concept

This kernel requires an x86-64 CPU but only detected an i686 CPU

AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework

How to install pam_mysql in CentOS or Red Hat

Error installing rails

sed: -e expression #1, char 24: Invalid range end

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy