skip to Main Content

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

3

Answers


  1. Chosen as BEST ANSWER

    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();
    

  2. try this! (remember this code is for localhost only).

    $query = “SET PASSWORD FOR root@localhost = PASSWORD(‘your_root_password’)”;
    mysql_query($query);

    Login or Signup to reply.
  3. phpMyAdmin doesn’t have its own user table, it uses the MySQL mysql database because at the end of the day phpMyAdmin is just another MySQL client.

    You have two options to change passwords there:

    • Use mysqladmin.
    • Use the correct SET PASSWORD command. DO NOT use PASSWORD(...) here as that sets your password to be, literally, some scrambled (hashed) version of your password. Let MySQL do the hashing for you.

    In order to change the password you need to know the current password. This makes scripting it difficult unless you have some place to easily change the password external to the script itself. I’d suggest an INI file which can be easily parsed.

    That being said, phpMyAdmin is not always the best solution, especially when free tools like MySQL Workbench exist. phpMyAdmin is a potential security risk, and a severe one if people use weak passwords like db123.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search