Search code examples
phpmysqlphpmyadminsystem-administration

How to change the phpMyAdmin root password via a PHP query script


I have a question on whether or not I can use a PHP script to change the phpMyAdmin root password. I am in the process of starting a small hosting/sass business, and one thing I need to do is get this working if you have a better solution for this, let me know.

I took a look at this query, but you can only run this when you have already logged in to the phpMyAdmin panel. SET PASSWORD FOR root@localhost = PASSWORD('yourpassword');

I basically want to be able to run this query, but in a PHP file.

Expected result: Once this PHP script is ran, it will change the phpMyAdmin root password.

How would I be able to do this? Is it possible? If you need more information please let me know, I will get back to you as soon as I can.

Thank you


Solution

  • This was my solution

    I made a connection to the mysql server and proceeded to change the root password. A simple solution that costed me a few hours.

    $conn = new mysqli(IP,MySQL Username,Password);
    $conn->query("SET PASSWORD FOR root@localhost = PASSWORD('password');");
    $conn->query("FLUSH PRIVILEGES;");
    $conn->close();