How can the privileges be flushed and a new password be set for the root user in MySQL?
To flush privileges and set a new password for the root user in MySQL, you can use the following steps: 1. Log in to MySQL as the root user. 2. Run the following SQL commands: FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; 3. Replace 'new_password' with your desired new password for the root user.
<?php
$servername = "localhost";
$username = "root";
$password = "current_password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Flush privileges and set new password for root user
$sql = "FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';";
if ($conn->query($sql) === TRUE) {
echo "Privileges flushed and password set successfully";
} else {
echo "Error: " . $conn->error;
}
$conn->close();
?>
Related Questions
- Is it advisable to rely on CSS for adjusting the spacing between a button and reCAPTCHA in PHP, or are there PHP methods available for this purpose?
- What is the significance of using single quotes (') in PHP code?
- What are some potential solutions for building a PHP index file with separate navigation and main content sections?