How to reset AUTO INCREMENT to 1 in MySQL PHP


In this example i am going to explain How to reset AUTO INCREMENT to one in MySQL PHP.

There is many way to reset AUTO_INCREMENT to 1in MySQL

Using SQL Query

Run the query in your database.

ALTER TABLE tablename AUTO_INCREMENT = 1;

Example:

ALTER TABLE student_data AUTO_INCREMENT = 1;

Using PHP code

index.php

<?php

$host='localhost';
$username='root';
$password='';
$conn=mysqli_connect($host,$username,$password,"student");
mysqli_query($conn,"ALTER TABLE category AUTO_INCREMENT = 1");
echo "Auto_increment reset to 1 Successfully ! ";

?>