MongoDB – Copy Database

MongoDB Copy Database Use copyDatabsae() function to copy MongoDB database from remote database instance to local database instance. You can also use this to copy database in the local instance as alternatives for rename database. Syntax: db.copyDatabase(fromdb, todb, fromhost, username, password, mechanism) Examples: Copy Database on Same Instance You can create a duplicate database in same instance by using copyDatabase() function. db.copyDatabase(“olddb”,”newdb”) Output: { “ok” : 1 } Also you can use above option to rename database in MongoDB. But you must have enough space to create a copy of…

Read More

MongoDB – Show Databases

MongoDB show databases Connect to the MongoDB shell and then execute show dbs command to list all the currently available database on MongoDB server. > show dbs local 0.000GB mydb 0.001GB tecadmin 0.083GB You can select any database using the use statement and work on it.

Read More

MongoDB – Create Database

MongoDB Create Database MongoDB does not provide commands to create a database. You can use use dbName statement to select a database in the mongo shell. Use the following example: Syntax: > use DATABASE_NAME Limitations MongoDB database names cannot be empty and must have fewer than 64 characters. Create Database First, of the all, Use below command to select database. To create a new database make sure it not exists. > use mydb You have a database name selected. Now you need to insert at least one document to keep this…

Read More

MySQL – Show Databases

Use SHOW DATABASES statement to list all database on MySQL database server. First login to MySQL server with privileged user and list all databases. Command:- SHOW DATABASES; Example:- Login to your MySQL server using command line. You will get MySQL database prompt like mysql> . Now use SHOW DATABASES statement to list all database. mysql> SHOW DATABASES; +——————–+ | Database | +——————–+ | information_schema | | mysql | | mydb | | performance_schema | +——————–+ 4 rows in set (0.03 sec) You can also use the following command directly on…

Read More

MySQL – Drop Database

Use DROP statement to delete database using MySQL query prompt. This tutorial will help you to delete MySQL database using the command line. Syntax:- DROP database_name; Example: Login to your MySQL server using command line. You will get MySQL database prompt like mysql> . Now use following command to connect mydb database. mysql> DROP mydb; Another Example: You can also use the following command directly on operating system command prompt without login to MySQL. This help users to automate task inside a script. mysqladmin -u root -p drop mydb

Read More

MySQL – Select Database

In this chapter of MySQL Tutorial, You will learn how to use database in MySQL. Before executing any operation on database you must need to use that database. Syntax: USE database_name; Example: ogin to your MySQL server using command line. You will get MySQL database prompt like mysql> . Now use following command to connect mydb database. mysql> use mydb;

Read More

SQL – Create Database

SQL CREATE DATABASE Use CREATE DATABASE statement to create a new database using mysql command. Login to MySQL server with administrative access to create a database. Syntax CREATE DATABASE database_name; Example Login to your MySQL server using the command line. You will get MySQL database prompt like mysql> . Now use CREATE DATABASE statement to create a database. mysql> CREATE DATABASE mydb; You can also use the following command directly on operating system command prompt without login to MySQL first. $ mysqladmin -u root -p create mydb To confirm that…

Read More