MYSQL有個命令可以列出所有當前連接(
show processlist;
),但由於其結果集不是普通的查詢結果集,程序處理時可能有問題,建議使用以下SQL語句:
select id,user as user_,host,db,command,time,state from information_schema.PROCESSLIST
Oracle的SQL語句:
select * from v$session where username is not null order by logon_time, sid
爲保持和上面MySQL的字段對應關係,還可以這樣改下:
select sid as id,username as user_, machine as host,schemaname as db,action as command,'' as time,status as state from v$session where username is not null order by logon_time, sid