MySql Connection

July 17, 2016 by Arti Khedkar

Filed under Database, MySQL

Last modified July 17, 2016

MySql Connection Command

 

Every connections of mysql are based on storage space in a disk. So you have to set that maximum connection based on work load on disks have command. In mysql 100 connections are maximum connections.

MySQL stands for My Structured Query Language. It is a open source database software. A NULL value is not equal to itself. If you compare a NULL value with another NULL value or any other value, the result is NULL because the value of each NULL value is unknown.

Here all the programs are executed on command prompt. It is very old database type which is used my most of the programs an organizations.

 

mysql

mysql connection command

MySQL : SELECT statement:

It is used for retrieving data one table to another. We can retrieve the more tables from another.

Syntax:

            SELECT expressions

FROM tables

[WHERE conditions];

 

       Example:

           

SELECT * from  emp_table;

 

 

MySQL : Create Table:

 

This command is used for table creation in database.

 

Syntax:

CREATE TABLE table_name (column_name column_type);           Example:                 

mysql> CREATE TABLE example (
id INT,
data VARCHAR(100) 

 

MySQL : Insert Query:

           

            This command is used for insert a query in database table.

 

Syntax:

                        INSERT INTO table_name ( field1, field2,…fieldN )                       VALUES                       ( value1, value2,…valueN );                                    Example:                         INSERT INTO Customer(cust_no,cust_name)                        VALUES                        (2, Ramu);

 

 

 

MySQL : Select Query:

           This command is used for fetch the data from table.

Syntax:

                        SELECT field1, field2,…fieldN table_name1, table_name2…                        [WHERE Clause]                        [OFFSET M ][LIMIT N];            Example:                          SELECT cust_no, cust_name  from customer;

MySQL : Drop Query:

          This command is used for drop the table from database table.        

          Syntax:

                                DROP TABLE table_name ;             Example:                                                                Drop table customer;

 

MySQL :Update Query:

          This command is used for update the previous table.

Syntax:

UPDATE table_name SET field1=new-value1, field2=new-value2                        [WHERE Clause]                        Example:                                                UPDATE customers                        SET last_name = ‘Khade’                        WHERE customer_id = 8000; 

 

 

MySQL : Delete Query:

          This command is used for delete the table from database table.      

          Syntax:

                              DELETE FROM table_name [WHERE Clause]        Example:

                          

 DELETE FROM employees

WHERE officeCode = 4;

 

 MySQL :Alter :

          This command is used to make change in previous table. Like add or delete.

Syntax:

ALTER TABLE table_name                         ADD new_column_name column_definition                        [ FIRST | AFTER column_name ];                      Example:                         ALTER TABLE contacts                        ADD last_name varchar(40) NOT NULL                        AFTER contact_id;                        

 

 

MySQL : Join Query:

         

This command is used for join the 2 or more database tables.         

         inner join

 

Syntax:

                        SELECT columns                        FROM table1                         INNER JOIN table2                        ON table1.column = table2.column;                         Example:

                    SELECT

column_1, column_2, …

FROM

table_1

[INNER | LEFT |RIGHT] JOIN table_2 ON conditions

WHERE

conditions

GROUP BY column_1

HAVING group_conditions

ORDER BY column_1

LIMIT offset, length;

 

MySQL :NULL:

          This command is used to check the data entered in that is not NULL.

Syntax:

SELECT * FROM tab WHERE col IS NOT NULL AND col != ”

              Example:                                                INSERT INTO contacts                        (contact_id, contact_name)                        SELECT account_no, supplier_name                        FROM suppliers                        WHERE category IS NULL;   MySQL connection to connect the PHP :                                    It is is used to connect the PHP program to MySQL.

 

Syntax:

mysqli_connect($connect);                        mysqli_query($connect,”SQL statement”); 

          Example:

<?php
$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;

Leave a Comment