Executing MySQL Queries Directly From the Command Line

MySQL is a central component of the LAMP open-source web application software stack (and other "AMP" stacks). LAMP is an acronym for "Linux, Apache, MySQL

Perl/PHP/Python". Applications that use the MySQL database include: TYPO3, MODx, Joomla, WordPress, phpBB, MyBB, and Drupal.

MySQL is also used in many high-profile, large-scale websites, including Google(though not for searches), Facebook, Twitter,Flickr, and YouTube.

Viewing list of Databases in your System
$ mysql -u root -p -e "SHOW DATABASES;"
To create Databases and start working with them
$ mysql -u root -p -e "CREATE DATABASE hackthesec;"
Without output from MySQL, nothing will be returned after running a command like the command above.

Create tables and view tables
$ mysql -u root -p -e "USE hackthesec; CREATE TABLE IF NOT EXISTS staffs ( ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 200 ) NOT NULL )"
$ mysql -u root -p -e "USE hackthesec; SHOW TABLES;"
To Insert into the table
$ mysql -u root -p -e "USE hackthesec; INSERT INTO staffs ( name ) VALUES ( 'John' );"
To view data in the table
$ mysql -u root -p -e "USE hackthesec; SELECT * FROM staff;
Now we want to output the result to a file, the tee command comes in handy or output redirection by running
$ mysql -u root -p -e "USE hackthesec; SELECT * FROM staff;" | tee output.txt
The output will be saved to output.txt of the working directory. Which can be viewed using cat command

$ cat output.txt

About Author:

I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Newer Post
Older Post


Post a Comment