Change the MySQL Password

  • I want to explicitly document changing the password for root for MySQL without needing to re-run the installer as the Wiki suggests.

    Enter current password for root:	<enter>
    Set root password?			y
    New password:				<new password>
    Remove anonymous users?			y
    Disallow root login remotely?		y
    Remove test database and access to it?	y
    Reload privilege tables now?		y

    Then we need to change everywhere FOG references the old password without rerunning the installer.

    sed -i.bak "s|snmysqlpass='<oldpassword>'|snmysqlpass='<newpassword>'|g" /opt/fog/.fogsettings
    sed -i.bak "s|DATABASE_PASSWORD', \"<oldpassword>\"|DATABASE_PASSWORD', \"<newpassword>\"|g" /var/www/html/fog/lib/fog/config.class.php

    I’m working on that second sed command’s escape sequence just now. EDIT - completed

    Is there anywhere else that needs to be changed? The purpose of this is to avoid re-running the installer just for the sake of a changed MySQL password.

  • The entire process is the initial post. It’s been edited and indicated.

  • @sudburr cam you post the whole thing now?

    Also, can we solve this?

  • @Tom-Elliott But that’s two steps; I’m aiming for a single step, direct solution.

    And I have it now

    sed -i.bak "s|DATABASE_PASSWORD', \"<oldpassword>\"|DATABASE_PASSWORD', \"<newpassword>\"|g" /var/www/html/fog/lib/fog/config.class.php

  • Senior Developer

    @sudburr You could try:


    Then when you call it you would simply use single quotes where needed.

    For example:

    $somepass = escapeshellarg('"\'helloworld!@@#$%^&*()\'"');

  • @sudburr would it be easier to write a php script to do it?

  • Changing the MySQL root password is contained in the command:


    I’m still trying to figure out how to escape the replacement strings, since it contains both single quotes ( ’ ) and double quotes ( " ).

    DATABASE_PASSWORD', "<oldnewpassword>"
    sed -i.bak 's|DATABASE_PASSWORD', "<oldpassword>"|DATABASE_PASSWORD', "<newpassword>")|g' /var/www/html/fog/lib/fog/config.class.php

  • Thought I might get to answer something on here for once! What Wayne said though is all I had to say :)

    Don’t forget the MYSql call was going to be my one major point to not forget.


  • @sudburr I think those two text spots are it. Nodes do not use the root pass so no changes there.

    Of course, you must issue a MYSQL command to change the password. That’s in the Troubleshoot MYSQL article for quick reference.