All services running, database connection failed

All services running, database connection failed

by Adam Sanasac -
Number of replies: 9

After doing an upgrade on the server (CentOS 7.5) to update all packages, Moodle is unable to connect to the database even though the mysqld service is running.

PHP is 7.2.10

MySQL is 8.0.12

Server is CentOS 7.5

config.php contents:

<?php  // Moodle configuration file

unset($CFG);

global $CFG;

$CFG = new stdClass();

$CFG->dbtype    = 'mysqli';

$CFG->dblibrary = 'native';

$CFG->dbhost    = 'localhost';

$CFG->dbname    = 'moodle';

$CFG->dbuser    = 'root';

$CFG->dbpass    = '<redacted>';

$CFG->prefix    = 'mdl_';

$CFG->debug     = E_ALL;

$CFG->debugdisplay      = 1;


$CFG->dboptions = array (

  'dbpersist' => false,

  'dbcollation' => 'utf8mb4_unicode_ci',

);

$CFG->wwwroot   = 'https://moodle.isd15.org';

$CFG->dataroot  = '/opt/moodledata';

$CFG->admin     = 'admin';


$CFG->directorypermissions = 0777;

$CFG->passwordsaltmain = '<redacted>';

require_once(dirname(__FILE__) . '/lib/setup.php');


// There is no php closing tag in this file,

// it is intentional because it prevents trailing whitespace problems!


/etc/my.cnf contents:

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock


# Disabling symbolic-links is recommended to prevent assorted security risks

#symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid


#innodb_file_format = Barracuda

innodb_file_per_table = 1

#innodb_large_prefix


character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

skip-character-set-client-handshake


[client]

default-character-set = utf8mb4


[mysql]

default-character-set = utf8mb4


The symbolic-links and two inno-db lines in my.cnf are commented out now as MySQL will not start with them uncommented after the system upgrades. The CFG->debug and CFG->debugdisplay lines in moodle/config.php are only there to try to get whatever information I possibly can to try to figure out what's causing the problem.

Doing a service mysqld status says that it is active (running). I can run MySQL queries/commands from the command line with no problem. The moodle database is there and the data seems to be intact.

Going to our Moodle homepage gives the Error: Unable to connect to database error.

Anyone have any brilliant ideas?

Average of ratings: -
In reply to Adam Sanasac

Re: All services running, database connection failed

by Adam Sanasac -

Forgot to mention....

Moodle version is 3.5.1.

In reply to Adam Sanasac

Re: All services running, database connection failed

by Adam Sanasac -

Debug info on the error page is as follows:

Debug info: MySQL server has gone away

Error code: dbconnectionfailed

Stack trace:

    • line 564 of /lib/dml/mysqli_native_moodle_database.php: dml_connection_exception thrown
    • line 340 of /lib/dmllib.php: call to mysqli_native_moodle_database->connect()
    • line 621 of /lib/setup.php: call to setup_DB()
    • line 30 of /config.php: call to require_once()
    • line 30 of /index.php: call to require_once()
Everything was working just fine on the server until I ran the package updates on the server.
In reply to Adam Sanasac

Re: All services running, database connection failed

by Ken Task -
Picture of Particularly helpful Moodlers

'brillant ideas'!!! with MySQL 8 one is kinda on the 'bleeding edge'. smile

However, having said that, in the past, 'Server has gone way' errors due to max_allowed_packet setting too low.

Please see:

https://dev.mysql.com/doc/refman/8.0/en/packet-too-large.html

Don't have a server running MySQL 8 to know for certain so above is 'best guess' - which isn't all that 'brillant'!

'spirit of sharing', Ken


In reply to Ken Task

Re: All services running, database connection failed

by Adam Sanasac -

Yeah, I wasn't exactly intending to upgrade to MySQL 8 just yet. Didn't see that it went GA, so when I ran the package updates on the server, it was kind enough to update MySQL 5.7 to 8.0.12 for me. How thoughtful of it. Now I'm kind of stuck since you can't roll MySQL versions backwards. I've already explored that idea.

I tried increasing the max_allowed_packet setting to 128M, restarted mysqld, but still no go with Moodle connecting.

Appreciate the help nonetheless!

In reply to Adam Sanasac

Re: All services running, database connection failed

by Ken Task -
Picture of Particularly helpful Moodlers

One other thing to check ... your config file is from 5.7.   Yum, when seeing it's upgrading a daemon package, usually leaves the config file being used (my.cnf) but does give you a new config file ... something like my.cnf.rpmsave?

It probably did it, but shouldn't one also use mysql_upgrade as superuser?

'spirit of sharing', Ken


In reply to Adam Sanasac

Re: All services running, database connection failed

by Adam Sanasac -

Got it solved.

Dumped the database from the command line, completely removed MySQL 8, downloaded/installed MySQL 5.7 RPMs, imported the database, and all seems well.

In reply to Adam Sanasac

Re: All services running, database connection failed

by Ken Task -
Picture of Particularly helpful Moodlers

Great.   You might consider excluding vr 8 in repo config file for now.

I use the repos offered by MySQL-Community, which has sections in the repo file for versions of MySQL .... so that helps to avoid issues with it.

Glad you resolved it.

'spirit of sharing', Ken