Changing the MySQL password

Changing the MySQL password

Note: Some distributions that include FreePBX and Asterisk have their own way of managing passwords. If you are new to FreePBX, and are using a distribution that includes FreePBX and Asterisk, you may want to read the instructions that came with your installation package to see if there is a script you should run, or some other mechanism for modifying system passwords.

If you are using the default password, you will see the message:

Warning: You are running freePBX and mysql with the default password

Running with the default password is a bad idea, simply because everyone else in the world knows it, and (if not properly firewalled, etc etc) could potentially connect to your mysql server and do bad things(tm).

Warning: Don't get cute and try to use a password with non-alphabetic or non-numeric characters - things may break in strange ways if you try to use punctuation characters in passwords. Unless you really know what you are doing, stick to numbers and standard alphabetic characters.

Changing the mysql password

There are multiple ways to change the password in mysql.

Using mysql admin

This requires that you know the existing password. From a shell, run:

mysqladmin -u asteriskuser -p password newpass

where asteriskuser is the username (asteriskuser is typically the default username in FreePBX), and newpass is your new password. You will be prompted for the old password interactively.

Using phpMyAdmin

Log into phpMyAdmin, and select Privileges from the main page. From there, select the user you want to edit, and click the edit icon next to their name.

Note on multiple username entries: Note that sometimes there will be multiple user names with different hosts. MySQL identifies users based on the hostname they're connecting from, and allows different passwords for users when they connect from different hosts. Often there is an entry with localhost and another with %. % is a wildcard in MySQL, and means any host in this case. If you have freePBX running on the same machine (which is most likely true) then the localhost entry is a better match than %, so it is the one that will be used. You can usually safely delete the % entry if you're not using it. If you are using a different host, it's better to use that specific host's name or IP than %. See MySQL documentation for more information.

Scroll down to the "change password" section, and enter the new password.

Using SQL

Connect to the mysql interactive shell:

mysql -u username -p

Usually you will use root or another user with administrative privileges as the username.

Run the following SQL command:

SET PASSWORD FOR asteriskuser@localhost=PASSWORD('newpass');

asteriskuser should be the username of the freePBX user. localhost should only be changed if your freePBX and MySQL servers are different machines. Be sure to include quotes around the new password.

type quit to return to the OS shell.

Verifying the password

If you want to be sure that the password has been changed, run:

mysql -u asteriskuser -p

amportal.conf, cdr_mysql.conf, res_mysql.conf

Once the password works, you need to update three files:

  • /etc/amportal.conf:

AMPDBUSER=asteriskuser

AMPDBPASS=mypass

  • /etc/asterisk/cdr_mysql.conf:

password=mypass

user=asteriskuser

  • /etc/asterisk/res_mysql.conf:

dbuser = asteriskuser

dbpass = mypass

Where asteriskuser is the username (asteriskuser is the typical FreePBX default username) and mypass is the changed password.

(Thanks to gstueve for the comment regarding the latter two files.)