Beginner guide to mysql command line Tool .	Priti Solanki
agendawhat is mysqltool
mysql  tool on windows
mysqlcommands
mysqltipsPriti Solanki
What is “mysql”  !! “mysql” is a simple SQL shell
  It supports interactive and non-interactive mode.On WindowsMake sure you have XAMPP/WAMP installed on your local machine.Open command prompt.Type on command line C:\>mysql	If “'mysql' is not recognized as an internal or external command“ error comes then you have to add the path to mysql bin directory in window’s environment variable.http://dev.mysql.com/doc/refman/5.5/en/mysql-installation-windows-path.htmlPriti Solanki
Mysql CommandConnect to mysqlshell>mysql –hlocalhost –uroot –p          Enter password:Welcome to the MySQL monitor.  Commands end with ;   or \g.            Your MySQL connection id is 22            Server version: 5.1.41 Source distribution            Type 'help;' or '\h' for help. Type '\c' to clear the current   input statement.If you are logged in successfully you will be displayed Welcome message and your prompt will get modified as  mysql>_Show database listmysql> show databases; +--------------------+| Database           |+--------------------+| information_schema || cdcol              || mechanics          || mysql              || ninja_world        || phpmyadmin         || test               |+--------------------+7 rows in set (0.00 sec)Priti Solanki
Mysql CommandHow to select data from tables?Before firing query to mysql you have to let mysql know which database you are going to use.mysql> use ninja_world;        Database changed         listing of tables in this database before I start querying ?mysql> show tables;+-----------------------+| Tables_in_ninja_world |+-----------------------+| ninja                 || power                 |+-----------------------+2 rows in set (0.00 sec)mysql> select * from ninja;+----+----------------+----------+| id | name           | power-id |+----+----------------+----------+|  1 | NarutoUzumaki |        0 ||  2 | Sakura Haruno  |        0 ||  3 | SasukeUchiha  |        0 ||  4 | Rocklee        |        0 ||  5 | ChojiAkimichi |        0 |+----+----------------+----------+Priti Solanki

Beginner guide to mysql command line

  • 1.
    Beginner guide tomysql command line Tool . Priti Solanki
  • 2.
  • 3.
    mysql toolon windows
  • 4.
  • 5.
  • 6.
    What is “mysql” !! “mysql” is a simple SQL shell
  • 7.
    Itsupports interactive and non-interactive mode.On WindowsMake sure you have XAMPP/WAMP installed on your local machine.Open command prompt.Type on command line C:\>mysql If “'mysql' is not recognized as an internal or external command“ error comes then you have to add the path to mysql bin directory in window’s environment variable.http://dev.mysql.com/doc/refman/5.5/en/mysql-installation-windows-path.htmlPriti Solanki
  • 8.
    Mysql CommandConnect tomysqlshell>mysql –hlocalhost –uroot –p Enter password:Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 5.1.41 Source distribution  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.If you are logged in successfully you will be displayed Welcome message and your prompt will get modified as mysql>_Show database listmysql> show databases; +--------------------+| Database |+--------------------+| information_schema || cdcol || mechanics || mysql || ninja_world || phpmyadmin || test |+--------------------+7 rows in set (0.00 sec)Priti Solanki
  • 9.
    Mysql CommandHow toselect data from tables?Before firing query to mysql you have to let mysql know which database you are going to use.mysql> use ninja_world; Database changed listing of tables in this database before I start querying ?mysql> show tables;+-----------------------+| Tables_in_ninja_world |+-----------------------+| ninja || power |+-----------------------+2 rows in set (0.00 sec)mysql> select * from ninja;+----+----------------+----------+| id | name | power-id |+----+----------------+----------+| 1 | NarutoUzumaki | 0 || 2 | Sakura Haruno | 0 || 3 | SasukeUchiha | 0 || 4 | Rocklee | 0 || 5 | ChojiAkimichi | 0 |+----+----------------+----------+Priti Solanki
  • 10.
    How to insertdata in a table?mysql> use ninja_world; Database changedmysql> INSERT INTO ninja( `name` , `power-id` ) -> VALUES ( -> 'komizkhazi', '1' -> ); Query OK, 1 row affected (0.00 sec)How to update data in a table?mysql> Update ninja SET name="psolanki" where id=16;Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0How to delete data from a table?mysql> delete from ninja where id=16;Query OK, 1 row affected (0.00 sec)Priti Solanki
  • 11.
    mysqlTipsUse ‘- -quick’option to retrieve results from the server a row at a time rather than retrieving the entire result set and buffering it in memory before displaying it.
  • 12.
    Some time queryresults are more readable when displayed vertically.mysql> select * from mechanic where if=101\G Press enter. The output will be formatted as shown belowFor tabular output, use “- - raw” OR “-r” mysql options. shell> mysql -r -uroot -e "SHOW VARIABLES LIKE 'version%'";+-------------------------+---------------------+| Variable_name | Value |+-------------------------+---------------------+| version | 5.1.41 || version_comment | Source distribution || version_compile_machine | ia32 || version_compile_os | Win32 |+-------------------------+---------------------+Priti Solanki
  • 13.
    Continue….Get xml outputof your mysql query. shell> mysql -X -uroot -e "USE ninja_world;select * from ninja LIMIT 1"; <?xml version="1.0"?><resultset statement="select * from ninja" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row> <field name="id">1</field> <field name="name">NarutoUzumaki</field> <field name="power-id">0</field> </row></resultset>Get html output from mysql query.shell> mysql --html -uroot -e "USE ninja_world;select * from ninja LIMIT 1";<TABLE BORDER=1><TR><TH>id</TH><TH>name</TH><TH>power-id</TH></TR><TR><TD>1</TD><TD>NarutoUzumaki</TD><TD>0</TD></TR></TABLE>Priti Solanki
  • 14.
    Continue….To reconfigure themysql prompt.mysql> \R ninja> ninja>Read the source file and executes the statements (in windows).mysql> source c:\\test.sql Database changed+----+----------------+----------+| id | name | power-id |+----+----------------+----------+| 1 | NarutoUzumaki | 0 || 2 | Sakura Haruno | 0 || 3 | SasukeUchiha | 0 || 4 | Rocklee | 0 |Test.sql is a sql file which contains following sql statementUse ninja_world;Select * from ninja;From here you are good to go for your own  !!. For any modification, correction or suggestion which can make this presentation good for beginners please care to drop a line on pritiatwork@gmail.comPriti Solanki