MySQL Questions III



  1. What’s the difference between CHAR_LENGTH and LENGTH? - The first is, naturally, the character count. The second is byte count. For the Latin characters the numbers are the same, but they’re not the same for Unicode and other encodings.
  2. How do you convert a string to UTF-8? - SELECT (techinterviews_question USING utf8);
  3. What do % and _ mean inside LIKE statement? - % corresponds to 0 or more characters, _ is exactly one character.
  4. What does + mean in REGEXP? - At least one character. Appendix G. Regular Expressions from MySQL manual is worth perusing before the interview.
  5. How do you get the month from a timestamp? - SELECT MONTH(timestamp) from questions;
  6. How do you offload the time/date handling to MySQL? - SELECT DATE_FORMAT(timestamp, ‘%Y-%m-%d’) from questions; A similar TIME_FORMAT function deals with time.
  7. How do you add three minutes to a date? - ADDDATE(publication_date, INTERVAL 3 MINUTE)
  8. What’s the difference between Unix timestamps and MySQL timestamps? - Internally Unix timestamps are stored as 32-bit integers, while MySQL timestamps are stored in a similar manner, but represented in readable YYYY-MM-DD HH:MM:SS format.
  9. How do you convert between Unix timestamps and MySQL timestamps? - UNIX_TIMESTAMP converts from MySQL timestamp to Unix timestamp, FROM_UNIXTIME converts from Unix timestamp to MySQL timestamp.
  10. What are ENUMs used for in MySQL? - You can limit the possible values that go into the table. CREATE TABLE months (month ENUM ‘January’, ‘February’, ‘March’,…); INSERT months VALUES (’April’);
  11. How are ENUMs and SETs represented internally? - As unique integers representing the powers of two, due to storage optimizations.


Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: