Can connect to MySQL but not create DB, 1st MODX 3 installation

Have successfully installed MODX 2.x over 50 times, but having an issue with my first 3.x installation.

As usual, I created a database first in cPanel, then run the “Setup” page

I can connect to MySQL (I had to manually change the “Connection character set” to “utf8” and “Collation” to “utf8mb4” in “settings.cache.php” as per another thread on here), but then get this message on clicking on “Create database”:

“MODX could not create your database. Please manually create your database and then try again.”

I’ve tried several times, deleting and creating new databases but to no avail. Am I missing some new required step needed with MODX 3.x?

It normally takes me a few minutes to get a new MODX installation up and running and I’ve been trying to get this to work for a couple of hours now. Any suggestions would be much appreciated.

MySQL server version: 8.0.32
MySQL client version: 7.4.33

are you getting any errors on the server logs? also, check the PHP version and the needed dependencies also check the browser console to see if maybe something is throwing an error, as far as I know, there are no special things to configure.

Make sure to create a DB user in PhpMyAdmin, who has full rights to the DB, and whose credentials are correct in the MODX config.core.php file.

No errors in server logs, and I have many other MODX sites running on this server without issue so I’m guessing all dependencies are present, unless 3.x has additional requirements. This is at a high quality data centre with which I’ve not had issues. The only difference is that the existing sites are on MODX 2.8x.

Thanks for your input!

I have a DB user with full rights, I always add the user straight after creating the DB, which I do before doing the MODX install.

the MODX config.core.php file has these two lines of code in it:

define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');
define('MODX_CONFIG_KEY', 'config');

Should there be more than this? It looks slightly different to the equivalent 2.8x installations, which look like this:

define('MODX_CORE_PATH', '/home/server_username_here/core/');
define('MODX_CONFIG_KEY', 'config');

Thanks for you reply!

If it cannot create the database, then it almost definitely has to be a MySQL user permissions issue. You should be able to create the database using your hosting panel or whatever tools they provide for managing the MySQL database and then run the installation. I can’t think of any reason why this would be different in 3.x than in 2.x.

The config.core.php files just give the path to the core and your config key. There are three of them. There’s one in the web root (which you’ve found), but there is also one in the manager/ directory and another in the connectors/ directory.

In MODX 3, the core directory must be in the web root, so its config.core.php can be simpler.

The only other reason I can think of for the trouble is an error in the core/config/ file, especially if you edited it manually.

This error message implies, that the code can’t connect to the database you manually created. So the code tries to create the database itself, but that doesn’t work either.

It’s most likely that one of your database settings is wrong.
Maybe try comparing the temporary settings in core/cache/setup/settings.cache.php with the settings of a working MODX 2 installation to see what’s different.

This is normal for a new installation. The relative path dirname(__FILE__) . '/core/' will be replaced during the installation.

Thanks to all for your input.

I have tried all the suggestions but to no avail. I have also deleted V3 and tried with V2.8.5 and had the same issue, and deleted and created new databases - no change. I’ve also been in touch with the data centre to see if there’s an issue there as I’ve been having some functionality issues due to stricter modsec security settings with some existing sites, but apparently there’s nothing that should prevent MODX connecting to the DB.

Not sure what to do next.

Interestingly, after getting the MySQL connection confirmed, if I click test DB connection again I get this message:

Could not connect to the database server. Check the connection properties and try again.

[2023-04-14 17:27:49] (ERROR in xPDO\xPDOConnection::connect @ /home/server_username_here/public_html/core/vendor/xpdo/xpdo/src/xPDO/xPDOConnection.php : 89) SQLSTATE[HY000] [2019] Unknown character set

[2023-04-14 17:27:49] (ERROR in xPDO\xPDOConnection::connect @ /home/server_username_here/public_html/core/vendor/xpdo/xpdo/src/xPDO/xPDOConnection.php : 89) SQLSTATE[HY000] [2019] Unknown character set 

So I have tried various character collations etc. but still no luck.

So, in core/cache/setup/settings.cache.php these are the settings:
Screenshot 2023-04-14 at 18.29.11
Screenshot 2023-04-14 at 18.29.31

And the MySQL settings show this for localhost:
Screenshot 2023-04-14 at 18.31.23

And this for the MODX DB:
Screenshot 2023-04-14 at 18.31.42

This is what the installer shows:

Does this shed any light on wrong settings?

Did you once try with a utf8mb4 charset instead?
This would also make your site more future-proof as the utf8mb3 character set is deprecated.

Yes I did, for that very reason, but it didn’t work so I went back to utf8mb3 in the hope that that was the issue.

Thanks for taking the time to reply.

utf8mb3 is deprecated and may not be supported by your DB. It should definitely be utf8mb4.

Take a look at your tables in PhpMyAdmin on the structure tab. See what the character set and collation are.

Also, in the SQL tab, try this:


Click on the “Go” button at the bottom, then look at the character set and collation variables.

This issue is weird.

When you click the upper “Test” button, the code runs setup/processors/database/connection.php that connects to the database server to load some information (like the server version and the values for the charset/collation dropdowns). This seems to work.

When you click the second “Test” button, setup/processors/database/collation.php is executed to connect to the specified database with the selected charset. And somehow this doesn’t work.

Maybe try to connect to the database with some custom code (in a separate PHP file), to see if you can figure out this way what the actual problem is. Something like this code should work:


$dsn = "mysql:host=localhost;dbname=modx8;charset=utf8mb4";
$user = "myuser";
$password = "mypassword";

try {
	$pdo = new \PDO($dsn, $user, $password);

	if ($pdo) {
		echo "Connected to the database successfully!";
} catch (\PDOException $e) {
	echo $e->getMessage();
} catch (\Exception $e) {
    echo $e->getMessage();

I had a similar/same problem but I found that during MODX setup I had to enter the username and password for cPanel itself not those of the user I created when creating the DB in cPanel. Once installed I edited core/config/config.core.cfg changing $database_user and $database_password to those of the newly created user.

Thank you to everyone that offered their suggestions on this, it is much appreciated.

After trying everything suggested, including changing Connection and Collation in phpMyAdmin and not getting anywhere I found that having Connection character set set to utf8mb4 and Collation set to utf8mb3_general_ci it worked. I took these settings from one of my other installations that worked. It seems counter-intuitive and I can’t pretend I understand why, but duly noted!

That’s really strange.

Out of curiosity, what collation do you see when you go to PhpMyAdmin, open the site’s DB and look at the “Structure” column?

Also, what collation do you see if you then open the modx_site_content table and look at the text fields (e.g., content) on the structure tab?

Sorry for the late reply, Bob.

Site DB > Structure > Collation = utf8mb3_unicode_ci

modx_site_content > content (Structure) > Collation = utf8mb3_unicode_ci

They’re the same.

I think that’s why you need to use the mb3 collation in the config and setup.

If it works, you might not want to mess with it, but you might take a look at this.

The downloadable script on that page would have to be modified slightly to use an mb4 charset and collation. After running it, your site would be in line with your other sites, and probably with custom tables created by extras.