Create, Backup and Restore MYSQL Database using cmd in Windows

Spread the love

Create NEW database Using cmd

Create a new database using command line

Run cmd & change directory

C:\Users>cd..

C:\>cd “Program Files”

C:\Program Files>cd MySQL

C:\Program Files\MySQL>cd “MySQL Server 5.1”

C:\Program Files\MySQL\MySQL Server 5.1>cd bin

Now, connect MySQL using this command mysql -u root -p

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u root -p

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.1.73-community MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> create database web;

Query OK, 1 row affected (0.04 sec)

mysql> grant all privileges on web.* to web@localhost identified by “1234”;

Query OK, 0 rows affected (0.10 sec)

Backup database using command line

Say you get a request to take backup of 1234 .Run cmd change directory & run following command.

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u root -p 123 > C:/Users/admin/Desktop/1234.sql

Enter password: ****

Restore database using command line

Say you get a request to take backup of 1234 .Run cmd change directory & run following command.

Restore :- mysql -u root -p [ Database name] < dumfilename.sql

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u root -p 123 > C:/Users/admin/Desktop/1234.sql

Enter password: ****

Leave a Reply

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