Pages

Friday, 6 July 2012

MySQL – Basic Commands To Know

MySQL – Basic Commands To Know 

MySQL is a simple SQL shell (with GNU read line capabilities). It supports interactive and non interactive use. When used interactively, query results are presented in an ASCII-table format. When used non interactively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.

After Installation of MySQL on Linux System, start it by,

# /etc/init.d/mysql restart or # service mysqld start

Default MySQL configuration file my.cnf is located in /etc/ or in /etc/mysql..

# cat /etc/my.cnf

Generally, root user of MySQL does not have password. To assign password,

# mysqladmin -u root password “LinuxArticles#123″

To login to your MySQL database you need to specify the username, “-p” will ask you the password

# mysql -u root -p

After successfully login, you will be in mysql command line interface.

mysql>

Before starting any project or after fresh installation, we required to create database to store data.

mysql> create database LinuxArticles.org;

After creating databases, list all by,

mysql> show databases;

To use particular database from above list,

mysql> use LinuxArticles.org;

To list all tables of selected DB,

mysql> show tables;

For some reason, if you want to delete created database,

mysql> drop database LinuxArticles.org;

To delete Table from selected Database,

mysql> drop database Table_Name;

Create a new User for Database and grant permission,

mysql> grant all on LinuxArticles.org.* to linuxart@localhost identified by ‘UserPassword@123′;

To take MySQL Database backup,

# mysqldump -u linuxart -p LinuxArticles.org > Backup_File.sql

For some reason, to restore a MySQL Database backup,

# mysql -u linuxart -p LinuxArticles.org < Backup_File.sql

No comments:

Post a Comment

Twitter Bird Gadget