Renaming a Mastodon Account by Transferring Data
BelowThis isarticle aexplains purelyhow manual,to Ruby-based procedure formanually “renaming”rename” a local Mastodon account by transferring its content from an old account to a newly created oneaccount in your Mastodon instance’s database. This approach does not preserve followers/followings. It is a risky, unsupported method—proceed only if you fully understand the implications and have a complete database backup.
Important disclaimers up front:Disclaimers
- Mastodon does not officially support
changingdirectusernamesusernamebychangesdirectvia databasemanipulation; there’s no built-in UI for this.edits. - In some
Mastodonversions,atootctl accounts rename
commandmay notexistexist,(particularlyleavingoldermanualversions).DB manipulation as your only option. DirectlyTheseupdatingstepstheinvolvedatabaselow-level data changes that canbe risky—always back upbreak yourDBinstancefirstifanddoneproceed with caution.incorrectly.InThethisinstructionsexample,belowwe’refocus onnotcopying (or preserving) followers/following relationships—onlytransferring statuses, favorites, bookmarks,notifications,notifications, etc.,The user specifically mentionednotwithout copying followers.
If you proceed with these steps, do so in a test environment or with a fresh backup on hand.
1. Create athe NewTarget Account in the Web UI
- Log
intoin to your Mastodon instance’s web interface as an admin. - Create
thea new local accountwithusing thedesired (target)desired/target username. - Confirm you can log in
toasthatthis new user to ensure it is recognized in theweb UI—just to be sure the account is active and recognized.system.
2. PrepareAccess athe Rails Console Session
- SSH into your Mastodon server.
- Switch to your Mastodon user (
oftencommonlymastodon
ormastodon-user
). - Navigate to your Mastodon installation directory (e.g.,
/home/mastodon/live
). Run:Start
RAILS_ENV=production bin/rails console
irb(main):001:0>
).3. FindIdentify the Old and New Accounts
In the Rails console, findlook up both the respectiveold and the new Account
records:objects:
old_username = 'oldusername' # fillReplace inwith yourthe old username
new_username = 'newusername' # fillReplace inwith yourthe new username
# domain: nil ensures that we only match local accounts
old_account = Account.find_by(username: old_username, domain: nil)
new_account = Account.find_by(username: new_username, domain: nil)
if old_account.nil?
puts "Old account not found! Check old_username."
end
if new_account.nil?
puts "New account not found! Check new_username."
end
puts "Old account ID: #{old_account.id}"
puts "New account ID: #{new_account.id}"
Note: domain: nil
ensures you are finding local (rather than remote) accounts.
4. Transfer Content to(Without the New AccountFollowers)
YouThe mentionedfollowing youcode do not want to preserve/copy followers. That’s simpler: we skip reassigning the Follow table. We’ll just movereassigns items like statuses (posts),statuses, favorites, bookmarks, notifications,and etc.notifications Tofrom dothe so:old account to the new account. We are deliberately skipping follower/following relationships:
# Move statuses to the new account
Status.where(account_id: old_account.id)
.update_all(account_id: new_account.id)
# Move favourites
Favourite.where(account_id: old_account.id)
.update_all(account_id: new_account.id)
# Move bookmarks
Bookmark.where(account_id: old_account.id)
.update_all(account_id: new_account.id)
# Move notifications
Notification.where(account_id: old_account.id)
.update_all(account_id: new_account.id)
# Optionally move pinned statuses
(if you want pinned statuses to show under the new account)
# Pinned statuses are in the "Pin" table
Pin.where(account_id: old_account.id)
.update_all(account_id: new_account.id)
TheNote: aboveYou codecan blocksadapt bulkthis updatepattern the account_id column on each table, reassigning rows from the old account to the new account.
Optional Additional Tables
Depending on your needs, you may have to considerfor other references:
- like
PollsPoll
(orMediaAttachment
, ifthe old account created polls)needed.
## Polls Poll.where(account_id: old_account.id).update_all(account_id: new_account.id)
- Media attachments (
avatars, headers, or post images could be associated with the old account or old statuses) – typically if thestatusis moved, the attachments should already point to that status. Butif you wanttothemfixreassignedreferencesfrom old tothenew accountitself:explicitly)MediaAttachment.where(account_id: old_account.id).update_all(account_id: new_account.id)
Announcements, scheduled statuses, pinned statusesetc. – depends on how thorough you need to be.
5. (Optional) “Hide”Retire or DisableArchive the Old Account
After you’ve verified everything is properly transferred,Once you canconfirm decidedata whathas tomoved, doyou with the old account:can:
- Rename
itthe old account tosomethingavoidlike@oldusername-archived(just so you don’t have conflicts). You can do a quick Rails update in the console:conflicts:old_account.update!(username: "oldusername-archived")
Lock or suspendSuspend the old accountso(preventit’sfurtherno longer active:use):old_account.update!(suspended_at: Time.now)
Or justdisableDisable theloginoldbyuserchanging itsUserrecord (the MastodonAccounthas auser_idlinking to theUsertable). For example:record:old_account.user.update!(disabled: true)
6. ValidateVerify the New Account
- Log in as the new user in the web UI.
VerifyCheck thatyou can see the transferred posts,statuses, favorites,bookmarks,andetc.bookmarks have transferred.Make sure anyConfirm pinned statuses (ifyouany)moveddisplaythem) appear correctly.properly.Confirm theThe old account should no longerhashavethatthesecontent.items.
7. (Optional) Reindex (If YouUsing Use ElasticSearchElasticSearch)
If your instance uses ElasticSearch or advanced search, you may want to reindex to ensure that searching for statuses from the new username works properly. For example:indexing:
RAILS_ENV=production bin/tootctl search deploy
(OrThis useensures the oldernewly raketransferred tasksposts ifare you’reindexed on an older version.)correctly.
ImportantFinal Notes
- This
processisisnot anofficial,officialsupportedmethod“rename.”toYou’rerename Mastodon accounts. The procedure effectivelymergingmergestheoldaccount’saccount data into abrand-new account. YouWementioneddeliberatelyyoudidspecificallynotdon’ttransferwantfollowertorelationships—thosecopyremainfollowers/followings. That is why the snippet above omitsFollow,Block,Mute, and so on.Even after you move all the statuses, remote servers on the fediverse might still have cached references to the old account name for a while. That’s generally unavoidable at a protocol level.Always keep a backup of your database before running these updates. One small typo can cause data corruption or undesired merges.
Summary
Create the new account in the Mastodon web UI.In the Rails console, find the old and new accounts.Useupdate_allcalls to move statuses, favorites, bookmarks, notifications, etc. from the old account to the new account.Optionally rename or disablewith the old account.Double-checkRemotethatserverseverythingmaylooksstillcorrect in the new account.
That’s the gist of doing it “by hand” in Ruby. Again, be cautious—direct DB-level changes are always risky! If all goes well, you end up with a new username that hasreference the old account’susername posts/favorites/etc.,for buta withouttime, duplicatingdue orto preservingcaching on the oldFediverse.
followrelationships.