tmux: open terminal failed: missing or unsuitable terminal: xterm-256color

Trying to upgrade my Pi-hole host from Raspbian Stretch to Buster, during the upgrade process, I detached the tmux session and left for a while, when I came back, I can’t create or attach my tmux session anymore, got error message as below:

pi@pi-hole ~ $ tmux a
open terminal failed: missing or unsuitable terminal: xterm-256color

pi@pi-hole ~ $ tmux
open terminal failed: missing or unsuitable terminal: xterm-256color

Workaround:

export TERM=xterm

This will make tmux work again.

Some instructions will tell you to kill the tmux server and start a new one:

tmux kill-server

This will lose the current session which is not preferred, especially during the system upgrade process.