Updating Moodle AD authentication via MySQL

I run a Moodle installation that is backed by MySQL and authenticates users with an Active Directory (AD). Recently there was some reorganization of the organizational units (OUs) in AD and, upon attempting to log in to our Moodle site, I got this message:

“LDAP-module cannot connect to any servers: Server: ‘ldap://domaincontroller1.beyondlogical.net/’, Connection: ‘Resource id #2′, Bind result: ””

In my case, the user account Moodle uses to bind to AD had been moved and simply needed updating, which is simple enough to edit through the database once you know where to look. Here is the SQL query to return the value to be edited:

SELECT value FROM moodle.config_plugins WHERE plugin = 'auth/ldap' AND name = 'bind_dn'

Check the returned value against your AD tree and figure out what needs to change. It should look something like this:

CN=Bind AD Query,OU=IT Department,OU=Users,OU=Beyond Logical Enterprises,DC=beyondlogical,DC=net

Compare this with AD and figure out what needs to change. If you aren’t familiar with AD, this string specifies an account (CN means “Common Name”, OU means “Organizational Unit”, DC means “Domain Controller”) and, if you read it from right to left, provides a path down the AD tree to specify how to locate that account.

Here is the SQL to update this value, make sure you replace the value I provide with whatever is appropriate for your AD:

UPDATE moodle.config_plugins SET value = 'CN=Bind AD Query,OU=IT Department,OU=Users,OU=Beyond Logical Enterprises,DC=beyondlogical,DC=net' WHERE plugin = 'auth/ldap' AND name = 'bind_dn'

You may also see this error if the password on the account has changed. The current password is stored in this value:

SELECT value FROM moodle.config_plugins WHERE plugin = 'auth/ldap' AND name = 'bind_pw'

and can be updated using this query:

UPDATE moodle.config_plugins SET value = 'your_password_goes_here' WHERE plugin = 'auth/ldap' AND name = 'bind_pw'