How to use 2 different databases but share the same user in wordpress

It is likely not worth the risk. A possible problem is that one site changes user data in a way the other site will not be able to understand, breaking it. So… the initial requirement for such a setting to work is that at least one of the sites do not change user data at all, maybe except for the bare minimum.

There is actually an old feature that allows to support the setup that you ask for by allowing you to specifically define which tables hold the user tables in which case the limitation is to have both sites using the same DB, but I have done small research and no one asked how to use this feature for a long while therefor I assume that not many use it in the wild.

Using multisite (as tom commented) is a better solution as it basically takes user management out of the site into a “common area”, basically a user and meta table which are common for both sites as you asked for, but with an out of site control of the user. But even in such a setting you will be limited in how sites interact with the meta table and you will need to ensure that whatever plugins you use do not use the same meta keys for the values stored in the user meta table.

multisite also solve the problem of Single Sign On to both sites which I assume you will also want although not explictly specified in the question.

tech