Category Archives: My SQL

My SQL

Get latest Identity value in MySQL?

In MySQL, We can get the last insert identity value by using the function LAST_INSERT_ID() .

Example :

Create table mysqlTable
(
  iId int AUTO_INCREMENT NOT NULL,
  First_Name varchar(100),
  Last_Name varchar(100)
);
Insert into mysqlTable(First_Name, Last_Name) 
Select 'Hitesh','Kumar' union
Select 'Dev','Yadav' union
Select 'Priyanka','Singla' union
Select 'Neha','Chauhan';


Query to get last inserted identity value

SELECT LAST_INSERT_ID() AS LastInsertedValue;


Result : 4

Give grant of the database to other systems.

Give grant of the dtabase to other systems
1. Connect to mysql after connecting with a root user
su – mysql

2. Set environment as
. myqenv

3. select choice as 1
4. connect to mysql prompt
mysql -u root

5. use mysql (To change the database)
6. Give grant to all
GRANT ALL ON *.* to root@’10.170.208.95′ IDENTIFIED BY ‘root’;
If u want to give the grant to a particular ip then use
GRANT ALL ON 10.239.199.100 to root@’10.170.208.95′ IDENTIFIED BY ‘root’;

7. FLUSH PRIVILEGES;