November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Learn MySQL

Learn MySQL

How To Connect MySQL Database Tutorial Example

Open your MySQL Client tools then copy & paste the below code to Connect to MySQL database server

   -- mysql.exe location: c:\xampp\mysql\bin\mysql.exe
   -- host: localhost
   -- username: root
   -- password: ***

   -- modify your host location, username, password accordingly.
   -- i am using dos prompt as client. you can use phpmyadmin or anything else you like.

   -- just copy & paste the bellow code in ms-dos prompt
   c:\xampp\mysql\bin\mysql -hlocalhost -uroot -p
      -- that's it!! we are connected to mysql database using the mentioned credentials
      -- is comment in MySQL
      -- in fact it is comment in MSSQL and Oracle as well

How To Create Database In MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to create a database in MySQL Database Server

   -- How To Create Database In MySQL Tutorial Example

   CREATE DATABASE basic;

   -- that's it!! mysql database "basic" has been created
      -- is comment in MySQL
      -- in fact it is comment in MSSQL and Oracle as well

How To Create Table In MySQL Database Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to create a database table “test” in MySQL Database Server

   -- How To Create Table In MySQL Database Tutorial Example

   CREATE TABLE test
   (
     TestID int(11) default NULL,
     TestName varchar(100) default NULL,
     TestAge int(11) default NULL
   );

   -- that's it!! mysql database table "test" has been created with 3 columns

How To Insert Single Row In MySQL Table Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to Insert into a database table “test” in MySQL Database Server

   -- How To Insert Single Row In MySQL Table Tutorial Example

   INSERT INTO  test(TestID ,TestName,TestAge) VALUES (1 , 'Donald', 33);

   -- that's it!! a row has been inserted in mysql database table "test" with 3 columns value
      -- is comment in MySQL
      -- in fact it is comment in MSSQL and Oracle as well

How To Insert Rows In MySQL Table Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to Insert multiple rows into a database table “test” in MySQL Database Server

-- How To Insert Rows In MySQL Table Tutorial Example

INSERT INTO  test(TestID ,TestName,TestAge) VALUES
(2 , 'Douglas', 34),
(3 , 'Jennifer', 35),
(4 , 'Michael', 49),
(5 , 'Pat', 40),
(6 , 'Susan', 55),
(7 , 'Hermann', 53),
(8 , 'Shelley', 29),
(9 , 'William', 21),
(10, 'Alexander', 42);

-- that's it!!

How To Insert Specific Columns In MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to Insert specific columns into a database table “test” in MySQL Database Server

-- How To Insert Specific Columns In MySQL Tutorial Example

INSERT INTO  test(TestName,TestAge) VALUES ('Noor.Hasan', 28);

-- that's it!!

Select Data From MySQL Table Tutorial Example

How To Select Data From MySQL Table Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to select or retrive data from a database table “test” in MySQL Database Server

-- How To Select Data From MySQL Table Tutorial Example

SELECT * FROM  test;

-- that's it!!

How To Select Specific Rows From MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to select or retrive specific rows data from a database table “test” in MySQL Database Server

-- How To Select Specific Rows From MySQL Tutorial Example

SELECT TestName, TestAge FROM  test WHERE TestID=10;

-- that's it!! TestName, TestAge columns of id=10 of mysql database table "test" has been selected

How To Select Data Using Like From MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to select or retrive rows data using LIKE from a database table “test” in MySQL Database Server

-- How To Select Data Using Like From MySQL Tutorial Example

SELECT * FROM test WHERE TestName LIKE '%Do%';

-- that's it!! all rows and all columns of mysql database table "test"
-- whose Name has the string "Do" have been selected

 

How To Ascending Sort/Order MySQL Data Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to select or retrive data ascendingly sort or order from a database table “test” in MySQL Database Server

-- How To Ascending Sort/Order MySQL Data Tutorial Example

SELECT * FROM test ORDER BY TestName ASC;

-- that's it!! all rows & columns of mysql database table "test" have been selected
-- Sort or Order By TestName Ascendingly

How To Descending Sort/Order MySQL Data Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to select or retrive data descendingly sort or order from a database table “test” in MySQL Database Server

-- How To Descending Sort/Order MySQL Data Tutorial Example

SELECT * FROM test ORDER BY TestName DESC;

-- that's it!! all rows & columns of mysql database table "test" have been selected
-- Sort or Order By TestName Descendingly


How To Update Data In MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to update from a database table “test” in MySQL Database Server

-- How To Update Data In MySQL Tutorial Example

UPDATE test SET TestAge=99;

-- that's it!!

How To Update Specific Rows In MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to update specific rows from a database table “test” in MySQL Database Server

-- How To Update Specific Rows In MySQL Tutorial Example

UPDATE test SET TestID=11 WHERE TestName='Noor.Hasan';

-- that's it!! TestID column of all rows of mysql database table "test" have/has been updated
-- whose TestName value is "Noor.Hasan"

How To Delete Specific Rows Data From MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to delete specific rows from a database table “test” in MySQL Database Server

-- How To Delete Specific Rows Data From MySQL Tutorial Example

DELETE FROM test WHERE TestName='Noor.Hasan';

-- that's it!! all rows of mysql database table "test" have/has been deleted
-- whose TestName value is "Noor.Hasan"

How To Delete Data From MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to delete data from a database table “test” in MySQL Database Server

-- How To Delete Data From MySQL Tutorial Example

DELETE FROM test;

-- that's it!! all rows of mysql database table "test" have/has been deleted
-- because there is no WHERE condition, so be careful before using it in Production one 


MySQL TRUNCATE TABLE Example

Open your SQL Query Editor then copy & paste the below code to TRUNCATE a table in MySQL:

   TRUNCATE TABLE test

MySQL TRUNCATE TABLE Example – Execution in SQL Query Editor

How To Drop Table From MySQL Database Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to drop table “test” from a database in MySQL Database Server

-- How To Drop Table From MySQL Database Tutorial Example

DROP TABLE test;

-- that's it!! mysql database table "test" has been droped


How To Drop Database In MySQL Tutorial Example

Open your MySQL Query Editor then copy & paste the below code to drop a database in MySQL Database Server

-- How To Drop Database In MySQL Tutorial Example

DROP Database basic;

-- that's it!! mysql database "basic" has been droped forever



1 comment to Learn MySQL

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>