Useful Commands of MySQL databases

Image

Here I am going to post some commands of Mysql Server, Pelase have a look

Check Install version of Mysql Server :-

[root@sahil ~]# mysqladmin -u root -p version

Enter password: Type your mysql root password

mysqladmin Ver 8.42 Distrib 5.1.69, for redhat-linux-gnu on i386

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.

Server version 5.1.69 <—————— Version of Mysql

Protocol version 10

Connection Localhost via UNIX socket

UNIX socket /var/lib/mysql/mysql.sock

Uptime: 1 day 17 hours 59 min 34 sec

Threads: 1 Questions: 2557 Slow queries: 0 Opens: 266 Flush tables: 1 Open tables: 64 Queries per second avg: 0.16

Creating Database on Mysql :-

mysql> create database sahil;

<——————– sahil is my database name

Query OK, 1 row affected (0.12 sec)

Show the Database in Mysql :-

root@sahil ~]# mysql -u root -p < ————-Login

Enter password:

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

Your MySQL connection id is 86

Server version: 5.1.69 Source distribution

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> show databases; Command to Show the DataBases

+——————–+

| Database |

+——————–+

| information_schema |

| amavisd |

| iredadmin |

| mysql |

| policyd |

| roundcubemail |

| sahil |                               <————- Here list of all the Databases

| test |

+——————–+

7 rows in set (0.14 sec)

Switch to a database.

Image

 

mysql> use roundcubemail —-> roundcubemail is my database

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

Show The Database Tables

mysql> show tables;

+————————-+

| Tables_in_roundcubemail |

+————————-+

| cache |

| cache_index |

| cache_messages |

| cache_thread |

| contactgroupmembers | <—————– All Tables of Database roundcubemail

| contactgroups |

| contacts |

| dictionary |

| identities |

| searches |

| session |

| users |

+————————-+

12 rows in set (0.00 sec)

mysql>

Set a root password if there is no root paassword.

# mysqladmin -u root password sahil321 <—–sahil321 is New password

Update a root password.

# mysqladmin -u root -p sahil321 sahil123 <— here oldpasswd is sahil321 and Updated is sahil123

Backup and Restore Database

Backup :-

Backup of single Database:-

#mysqldump -u root -psahil123 sahil > backupmysql.sql

Note :- Here sahil is database and backupmysql.sql is backup file or Dump file

Backup of All Databases:-

# mysqldump -u root -p –all-databases > all_databases.sql

Restore Database :-

#mysql -u root -p sahil < backupmysql.sql

Note :- Here i am importing backup file in database sahil

Restore All Databases :-

#mysql -uroot -p –all-databases < all_databases.sql

Have a Great Day Ahead 🙂

Cheer Happy Linux-Ing 🙂 🙂 🙂

 

Leave a Comment

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

Scroll to Top