SQL Query to See Which Users Logged Into Retain and When

  • 7019226
  • 13-Mar-2015
  • 07-Aug-2017

Environment


Retain 3.x
MySQL

Situation


I want to see which users are logging into Retain since a specified time.  How can I do that?

DISCLAIMER:

This knowledgebase (KB) article is provided for informational purposes only and as a courtesy service to you, our customer. GWAVA Technical Support does not have any database administration (DBA) expertise, nor does it provide DBA services or support. GWAVA is not responsible for the results of implementing any of the concepts contained in this KB article. Implementation of any of the concepts suggested in this KB article shall be done entirely at your own and sole risk, and GWAVA does not provide any kind of warranties whatsoever resulting from your decision of implementing any of the KB article’s concepts. It is up to you to do any research and to ensure yourself that any implementation and setup of any of the KB article’s concepts in your database system is correctly and properly executed. It is imperative that you have backups of your database system and storage directory before making any implementation. If you don’t have any DBA expertise, you should consult with a DBA expert before any implementation of the KB article’s concepts.  Under no circumstances, shall GWAVA, or any of its employees, be liable, in contract, tort, delict or otherwise, whether negligence is provable or not, for any direct, indirect, incidental, special, punitive, consequential or other damages, loss, cost or liability whatsoever that would result from or are related to the implementation of any of the concepts suggested in the KB article.


To the extent permitted by applicable law, GWAVA shall not be liable to you for any special, consequential, direct, indirect or similar damages, including any loss of data, arising out from migrating any type of messages, attachments, database, metadata in your Retain system to another server and/or location.


Resolution


You can do that with a SQL query.  This example will be for MySQL, but the same concept applies for MS SQL or Oracle.  For example, MS SQL uses "dbo" before the table name whereas MySQL does not.

To see all users that have ever logged in:

SELECT * FROM retain.t_user WHERE ts_lastlogin > 0;

To set a timeframe, for example since January 1, 2015, you first have to convert that date into Unix time, because the date/time of the login is stored in Unix time in the database.  Unix time is the number of seconds that have transpired since January 1, 1970.  It is commonly used in programming. 

Then, run this query:

SELECT * FROM retain.t_user WHERE ts_lastlogin > 1420092000;

Note that, for this example, 1420092000 is January 1, 2015 at the top of the hour (00:00) Mountain Daylight Time (GMT -6).  That string will be different for other timezones.

You can send the query to a CSV file:

SELECT * FROM retain.t_user WHERE ts_lastlogin > 1420092000 INTO OUTFILE '/[path and filename]' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

Additional Information

This article was originally published in the GWAVA knowledgebase as article ID 2498.

Feedback service temporarily unavailable. For content questions or problems, please contact Support.