MySQL: run a script when logging in?
The mysql client has the init-command option, which does what you want, I think.

From the manual:


  --init-command=str
  
  SQL statement to execute after connecting to the server. If
  auto-reconnect is enabled, the statement is executed again after
  reconnection occurs.