Where does OS X store accessibility preferences?
The database is located at /Library/Application Support/com.apple.TCC/TCC.db.
To query the database from the command line, use sqlite3.

You can query what access a certain app has.
sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db \
  'select service from access where client like &quot;com.apple.Terminal&quot;
    and auth_value = 2;'

kTCCServiceDeveloperTool
kTCCServiceListenEvent
kTCCServicePostEvent
kTCCServiceScreenCapture
kTCCServiceSystemPolicyAllFiles


You can query what apps have access to a certain permission like accessibility.
sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db \
  'select client from access where service like &quot;kTCCServiceAccessibility&quot;
    and auth_value = 2;'

com.apple.AEServer
com.apple.MobileSMS
com.apple.dt.Xcode-Helper
…



To perform these queries, Terminal needs full disk access (kTCCServiceSystemPolicyAllFiles).
Replace auth_value = 2 with allowed = 1 if on an older macOS like High Sierra (not sure at which point it changed between High Sierra and Big Sur).