During my time developing a import/export MMS script for a client I came across a very detailed and informative error:
Failed to read from or write to database. Refresh and try again. If the problem persists, please contact the administrator
After I finished rolling my eyes I started with permissions. I checked the application service permissions, made sure I was running my code with administrative rights, checked the database owners. I gave up on the fact that it was a permissions issue.
I realized that this occurred when I tried creating groups, termsets, or terms with specific GUIDs. Of course, every term must have a unique GUID, this is something you will want to confirm when you are facing the error above. Keep in mind that site collections may have their own managed metadata. I.e. going through your MMS from central admin you might not see the GUID you are looking for, but it may exist in any site collection as well which is likely using the exact same MMS.
In my case the issue was twofold. I had duplicate GUID’s but it was harder for me to realize this I did not realize I had ‘orphaned’ orphans which I talked about in this post which should only apply to you if you have been involved in deleting groups/termsets through code.