How to record a user-created date in MySQL

Source: Internet
Author: User

We all know that the meta data of user in MySQL is stored in the Mysql.user table, but unfortunately there is less information available, such as we don't know the exact creation time of a certain user.

We can use the following method to achieve this goal.

First, we add a column to the Mysql.user table that is used to record the creation time of the user and give the default value.

Mysql> ALTER TABLE Mysql.user add create_time timestamp default current_timestamp; Query OK, 9 rows affected (0.06 sec) records:9  duplicates:0  warnings:0

At this point, we can do a test.

Mysql> create user wison_test identified by ' wisontest '; Query OK, 0 rows Affected (0.00 sec)

Below, we can see the creation time of the user.

Mysql>  Select Host,user,password,create_time from Mysql.user where user= ' wison_test '; +------+------------+-- -----------------------------------------+---------------------+| Host | User       | password                                  | create_time         |+------+------------+-------------------------------------------+---- -----------------+| %    | wison_test | *49b26a9583639e227274a403f369ae54a4061bab | 2014-12-25 17:13:17 |+------+------------+---------- ---------------------------------+---------------------+1 row in Set (0.00 sec)

Of course, the new column needs to be added when MySQL is in normal use. If added later, the value of the column create_time of the newly created user is 0000-00-00 00:00:00

How to record a user-created date in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.