I decided I would try migrating from SQLlite to mariadb and my experience did not match the documentation. I will leave this here in case anyone needs it.
sudo -u www php ./occ db:convert-type mysql nextcloud [hostname] nextcloud
the above, as supplied by the occ prompt, never worked. I replaced hostname w localhost, the IP address (it’s running on the same machine so not hard to access). None of that worked.
The error was consistently Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002 ] Connection refused
Nothing helpful there. The database does/did exist and I logged into it through MySQL on the command line to verify.
What eventually worked was sudo -u www php ./occ db:convert-type mysql nextcloud localhost:3306 nextcloud
The hostname with the port did not work,
The proper order of things would also be to create the database/database user first before attempting this as it will surely fail if the username doesn’t exist.
I also had to add this line to config.php: "dbtableprefix" => "oc_",
Not this was 100% successful. The server completely b0rked now, kicking back Internal Server Error
The log says:: sudo -u www php ./occ An unhandled exception has been thrown: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory in /usr/local/www/nextcloud/lib/private/DB/Connection.php:139
But… mysql -u nextcloud -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g.
and use database nextcloud/show tables does what one would expect.
Was that a typo above or am I misunderstanding your statement about not using the port?
There is a separate parameter for specifying a non-standard port[1] if needed (--port). Since 3306 is MySQL’s default port, specifying it shouldn’t be necessary, but either way.
Based on some of the behavior you encountered, are you by chance running MariaDB through a UNIX socket / with skip-networking=1 maybe?
Can you share the db* parameter set now in your Nextcloud config?
I did a quick test (twice just in case). And I didn’t encounter the same behavior (full capture below).
In addition, checked via Administration settings->Logging that Nextcloud automatically switched over to the new DB within 60s (the default opcache revalidate frequency). Instance didn’t even experience any downtime.
[client-server] port = 3306 socket = /tmp/mysql.sock [mysqld] #skip-networking=0
I don’t use docker and maybe that’s a prerequisite I am not aware of. I have no idea what docker is (I assume it’s some kind virtualization/emulation). It’s not clear how adding a layer of virtualization or whatever would make it easier to connect to a running database that other processes can access.
Once again, this is where — and many others on here — seem to be stuck. sudo -u www php ./occ An unhandled exception has been thrown: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory in /usr/local/www/nextcloud/lib/private/DB/Connection.php:139
No clue why it can’t connect, what driver it is using or requires. As for elapsed time…
I don’t use docker and maybe that’s a prerequisite I am not aware of.
Docker is irrelevant.
Once again, this is where — and many others on here — seem to be stuck.
You didn’t answer my questions:
Was that a typo above or am I misunderstanding your statement about not using the port? (your example has a port on the hostname still). I’d like to find out the actual command that finally worked for you for the conversion part.
Can you share the db* parameter set now in your Nextcloud config.php? The ones like dbtype, etc.
most of that, all but the last line, was added by occ.
Docker may be irrelevant but every working solution seems to reference it: seems like no one does this in a bare metal (emulated or otherwise) setting.
Okay I think I know what happened in your case. Your MySQL server has both UNIX socket support and networking (TCP) enabled. That’s totally fine, but there are some built-in assumptions in the mysql drivers in the event that localhost is specified - namely they try to use the UNIX socket mode. This is old MySQL client behavior.
And technically it should have been fine, but there is a bug in db:convert-type right now for UNIX socket support (which I kind of forgot about, but I already created a patch it last summer[1] then got distracted so I never wrapped it up for merging).
When you appended :3306 it overrode that behavior and worked via networking (TCP).
I’m already working on some doc adjustments to clarify that whole section. I’ll take another look at the bug fix for UNIX sockets too. I’ll also update the docs in a second pass, once that bug addressed, to include UNIX socket handling as well during conversions.
It didn’t work at all until I added that. Not obvious that it tried networking or that using the socket is preferred.
I just turned on “skip-networking” and changed dbhost to 'dbhost' => 'localhost:/tmp/mysql.sock',
Now it works as expected. And wordpress is agnostic about it all so it works as it did before. Postel’s Law of Robustness comes to mind here. This is a widely-shared issue, lots of search results for it.