Skip to main content

Renaming a Mastodon Account by Transferring Data

BelowThis isarticle aexplains purelyhow manual,to Ruby-based procedure formanuallyrenaming”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 changingdirect usernamesusername bychanges directvia database manipulation; there’s no built-in UI for this.edits.
  • In some Mastodon versions, a tootctl accounts rename command may not existexist, (particularlyleaving oldermanual versions).DB manipulation as your only option.
  • DirectlyThese updatingsteps theinvolve databaselow-level data changes that can be risky—always back upbreak your DBinstance firstif anddone proceed with caution.incorrectly.
  • InThe thisinstructions example,below we’refocus on not copying (or preserving) followers/following relationships—onlytransferring statuses, favorites, bookmarks, notifications,notifications, etc., The user specifically mentioned notwithout 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

  1. Log intoin to your Mastodon instance’s web interface as an admin.
  2. Create thea new local account withusing the desired (target)desired/target username.
  3. Confirm you can log in toas thatthis new user to ensure it is recognized in the web UI—just to be sure the account is active and recognized.system.

2. PrepareAccess athe Rails Console Session

  1. SSH into your Mastodon server.
  2. Switch to your Mastodon user (oftencommonly mastodon or mastodon-user).
  3. Navigate to your Mastodon installation directory (e.g., /home/mastodon/live).
  4. Run:
  5. Start
the Rails console in production mode:
RAILS_ENV=production bin/rails console

  • You should see a Ruby prompt (irb(main):001:0>).
  • indicating you’re in the Rails console.


    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:

    tables,
      like
    • PollsPoll (or MediaAttachment, if the 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 the status is moved, the attachments should already point to that status. But if you want tothem fixreassigned referencesfrom old to thenew account itself:explicitly)
      MediaAttachment.where(account_id: old_account.id).update_all(account_id: new_account.id)
      
    • Announcements, scheduled statuses, pinned statuses etc. – 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 to somethingavoid like @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 account so(prevent it’sfurther no longer active:use):
      old_account.update!(suspended_at: Time.now)
      
    • Or just disableDisable the loginold byuser changing its User record (the Mastodon Account has a user_id linking to the User table). For example:record:
      old_account.user.update!(disabled: true)
      

    6. ValidateVerify the New Account

    1. Log in as the new user in the web UI.
    2. VerifyCheck that you can see the transferred posts,statuses, favorites, bookmarks,and etc.bookmarks have transferred.
    3. Make sure anyConfirm pinned statuses (if youany) moveddisplay them) appear correctly.properly.
    4. Confirm theThe old account should no longer hashave thatthese content.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.


    Important

    Final Notes

    • This processis is not an official,official supportedmethod “rename.”to You’rerename Mastodon accounts. The procedure effectively mergingmerges the old account’saccount data into a brand-new account.
    • YouWe mentioneddeliberately youdid specificallynot don’ttransfer wantfollower torelationships—those copyremain followers/followings. That is why the snippet above omits Follow, 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

    1. Create the new account in the Mastodon web UI.
    2. In the Rails console, find the old and new accounts.
    3. Use update_all calls to move statuses, favorites, bookmarks, notifications, etc. from the old account to the new account.
    4. Optionally rename or disablewith the old account.
    5. Double-checkRemote thatservers everythingmay looksstill correct 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. follow

  • Always relationships.

    keep backups of your database. Minor mistakes in database manipulation can cause significant data loss.