title: mysql Set default value of a column as the current logged in user
body: <p>How do you set the default value of a column to be the logged in user? </p>
  
  <p>I am creating a "logging" table, and one of the columns should be the logged in user </p>
  
  <pre><code>(the output of "SELECT user();"). 
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p><strong>EDIT--What I tried:</strong></p>
  
  <pre><code>create trigger logtrigger_test before insert on logging_test for each row set new.changed_by=current_user();
  </code></pre>
  
  <p><strong>EDIT 2: describe table</strong></p>
  
  <pre><code>+---------------+-------------+------+-----+-------------------+-----------------------------+
  | Field         | Type        | Null | Key | Default           | Extra                       |
  +---------------+-------------+------+-----+-------------------+-----------------------------+
  | id            | int(11)     | NO   | PRI | NULL              | auto_increment              |
  | source_table  | varchar(50) | NO   |     | NULL              |                             |
  | foreign_id    | int(11)     | NO   |     | NULL              |                             | 
  | field_changed | varchar(30) | NO   |     | NULL              |                             | 
  | changed_by    | varchar(30) | YES  |     | NULL              |                             | 
  | changed_on    | timestamp   | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
  +---------------+-------------+------+-----+-------------------+-----------------------------+
  </code></pre>
  
  <p><strong>EDIT 3: SAMPLE entries in table</strong></p>
  
  <pre><code>+----+---------------+------------+------------------+----------------------+---------------------+
  | id | source_table  | foreign_id | field_changed    | changed_by           | changed_on          |
  +----+---------------+------------+------------------+----------------------+---------------------+
  | 0  | phone_numbers | 34         | home_phone       | jeff@localhost       | 2013-04-10 14:15:13 |
  | 1  | contact_info  | 24         | first_name       | bob@localhost        | 2013-04-11 10:18:43 | 
  | 2  | addresses     | 32         | home_address     | autoscript@localhost | 2013-04-12 11:10:37 |
  | 3  | addresses     | 36         | business_address | bob@localhost        | 2013-04-12 14:56:17 |
  | 4  | addresses     | 36         | business_address | jeff@localhost       | 2013-04-12 15:25:52 |
  +----+---------------+------------+------------------+----------------------+---------------------+
  </code></pre>