Got it

The Series of MySQL -4- MySQL User Management - EP 04_05

Latest reply: May 21, 2022 08:31:51 521 16 12 0 0

The Series of MySQL -4- MySQL User Management - EP 04_05



HI Hi, Greetings!  i_f47.gif

Happy February i_f25.gif


Hi Everyone,



Today, I would like to share with you an article about the fourth episode of Series of MySQL (MySQL Database), and the content is given below.


a.    Create Database

b.   Select Database

c.    Show Databases

d.   Drop Database

e.   Copy Database 

 

Copy Database


A database is a program that keeps track of a logical collection of records that the user may access and manipulate. It organizes data into tables, rows, columns, and indexes to make it easier to find relevant information.

 

The MySQL copy or clone database function lets us duplicate an existing database, including table structure, indexes, constraints, default values, and so on. Making a duplicate copy of the original database into a new database is highly beneficial when our database is mistakenly lost or fails. The most common reason for making a duplicate copy of the database is for data backups. It's also useful for preparing major changes to the structure of the original database.

 

In MySQL, cloning an existing database is a three-step process: The data from the old database is first dumped (copied) to a temporary file containing SQL commands for re-entering it into the new database. The next step is to create a brand-new database. The data is subsequently copied into the new database after the SQL file has been parsed.

 

These are the steps to copy a database to another database:

 

Step 01

To begin, use the CREATE DATABASE statement to create a new database.

 

Step 02

Next, store the data in a SQL file. This file can be named whatever we want as long as it ends in.sql extension

                       

Step 03

Export all of the database objects as well as their data to copy using the mysqldump tool, and then import this file into the new database.

 

For demonstration reasons, the empdb database will be copied to the empdb1 database using the procedures below:

 

Open the MySQL console and note down the password we set during installation. Now we can use the following command to create a empdb1 database:

 

mysql> CREATE DATABASE empdb1;  

 

With the SHOW DATABASES statement, verify the following:

 

mysql> SHOW DATABASES; 

 

This command displays a list of all the server's databases, with the freshly formed database.


26


Open a DOS or terminal window to connect to the MySQL server via the command line. Copy the following folder and paste it into our DOS command if we installed MySQL in the C folder, for example. Then, press the Enter key.

 

C:\Users\zaheer > CD C:\Program Files\MySQL\MySQL Server 8.0\bin    

 

The next step is to use the mysqldump tool to copy the database objects and data into the SQL file. Let's imagine we want to dump (copy) the data and objects from the empdb database into a SQL file in the D:\Database_backup folder. To do so, type the following command:

 

mysqldump -u root -p empdb > D:\Database_backup\empdb.sql  

Enter password: **********  

 

The previous command instructs the mysqldump tool to log in to the MySQL database server using the supplied username and password, then export the database objects and data from the empdb database to D:\Database_backup\empdb.sql. It's worth mentioning that the operator (>) is used to transfer data from one location to another.

 

 

After that, you must import the D:\Database_backup\empdb.sql file into the empdb1 copy database. To do so, type the following command:

 

mysql -u root -p empdb1 < D:\Database_backup\empdb.sql  

Enter password: **********  

 

 

It's worth mentioning that the operator () is used to transfer data from one location to another.

 

24

 

Finally, we can check if the above activity was successful.

 

25


You are welcome to like and leave feedback in the comment area.


Link:


EP 03_01:

The Series of MySQL - 4 - MySQL User Management - EP 04_01




EP 03_02:

The Series of MySQL -4- MySQL User Management - EP 04_02



EP 03_03:

The Series of MySQL -4- MySQL User Management - EP 04_03



EP 03_04:

The Series of MySQL -4- MySQL User Management - EP 04_04


Source:

  • https://www.w3schools.com/mySQl/default.asp

  • https://www.mysqltutorial.org/mysql-basics/



M M Zaheer Hussain

Stay Safe!

tt


The post is synchronized to: Author groupzaheernew's Author Collection

  • x
  • convention:

zaheernew
MVE Author Created Feb 19, 2022 08:25:41

  • x
  • convention:

andersoncf1
andersoncf1 Created Feb 19, 2022 16:11:14 (0) (0)
 
wissal
wissal Created Feb 27, 2022 16:18:21 (0) (0)
Thank you, my friend  
Saqib123
Created Feb 19, 2022 11:42:02

Thanks for sharing
View more
  • x
  • convention:

Unicef
MVE Created Feb 19, 2022 12:04:23

WELL DONE
View more
  • x
  • convention:

andersoncf1
MVE Author Created Feb 19, 2022 16:11:23

Well! Thank you
View more
  • x
  • convention:

Rumana
Created Feb 21, 2022 05:29:06

Good job
View more
  • x
  • convention:

BWGARM
Created Feb 21, 2022 05:32:22

The Series of MySQL -4- MySQL User Management - EP 04_05-4697393-1
View more
  • x
  • convention:

MahMush
Moderator Author Created Feb 21, 2022 06:42:13

well done
View more
  • x
  • convention:

Anno7
Moderator Author Created Feb 21, 2022 06:57:22

learned alot
View more
  • x
  • convention:

zaheernew
zaheernew Created Feb 21, 2022 18:05:33 (0) (0)
Fantastic  
Zonger
Created Feb 21, 2022 18:25:38

good share
View more
  • x
  • convention:

zaheernew
zaheernew Created Feb 25, 2022 16:07:22 (0) (0)
Thank you so much  
12
Back to list

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.