MySQL study Note 19: System information function _ MySQL

Source: Internet
Author: User
MySQL study Note 19: System information function bitsCN.com

The system information function is used to query the system information of the mysql database.

VERSION () returns the database VERSION number.
mysql> SELECT VERSION();+-------------------------+| VERSION()               |+-------------------------+| 5.5.28-0ubuntu0.12.10.2 |+-------------------------+1 row in set (0.00 sec)

I am using the ubuntu-based release, Linux Mint

CONNECTION_ID () returns the number of database connections
mysql> SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID() |+-----------------+|              36 |+-----------------+1 row in set (0.00 sec)

In fact, each connection to mysql will display

DATABASE (), SCHEMA () returns the current DATABASE name
mysql> SELECT DATABASE(), SCHEMA();+------------+----------+| DATABASE() | SCHEMA() |+------------+----------+| person     | person   |+------------+----------+1 row in set (0.00 sec)

USER (), SYSTEM_USER (), SESSION_USER () returns the current USER
mysql> SELECT USER(), SYSTEM_USER(), SESSION_USER();+----------------+----------------+----------------+| USER()         | SYSTEM_USER()  | SESSION_USER() |+----------------+----------------+----------------+| root@localhost | root@localhost | root@localhost |+----------------+----------------+----------------+1 row in set (0.00 sec)

CURRENT_USER (), CURRENT_USER returns the current user
mysql> SELECT CURRENT_USER(), CURRENT_USER;+----------------+----------------+| CURRENT_USER() | CURRENT_USER   |+----------------+----------------+| root@localhost | root@localhost |+----------------+----------------+1 row in set (0.00 sec)

The above three functions are the same as the two functions.

CHARSET (str) returns the character set of the str string
Mysql> select charset ('Zhang San'); + ----------------- + | CHARSET ('Zhang San') | + --------------------- + | utf8 | + ------------------- + 1 row in set (0.00 sec)

COLLATION (str) returns the character arrangement of the str string.
Mysql> select collation ('Zhang San'); + ------------------- + | COLLATION ('Zhang San') | + signature + | utf8_general_ci | + --------------------- + 1 row in set (0.00 sec)

LAST_INSERT_ID () returns the final AUTO_INCREMENT value.
mysql> CREATE TABLE t1(id INT PRIMARY KEY AUTO_INCREMENT);Query OK, 0 rows affected (0.10 sec)mysql> INSERT INTO t1 VALUES(NULL);Query OK, 1 row affected (0.04 sec)mysql> INSERT INTO t1 VALUES(NULL);Query OK, 1 row affected (0.03 sec)mysql> INSERT INTO t1 VALUES(NULL);Query OK, 1 row affected (0.04 sec)mysql> SELECT * FROM t1;+----+| id |+----+|  1 ||  2 ||  3 |+----+3 rows in set (0.00 sec)mysql> SELECT LAST_INSERT_ID();+------------------+| LAST_INSERT_ID() |+------------------+|                3 |+------------------+1 row in set (0.00 sec)

The preceding statement first creates a table t1 with an auto-increment Field id.

Insert NULL three times to enable auto-increment.

After confirming that the data already exists, use LAST_INSERT_ID () to obtain the last automatically generated value.

BitsCN.com

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.