A \g
Effect: Changes the display of the output results so that the output is displayed as columns.
Note: \g is uppercase, the SQL statement is not delimited after using the \g parameter;. If added, the error will be reported:
from mysql.user \g*************************** 1. Row *************************** host:localhost user:root * 23ae809ddacaf96af0fd78ed04b6a265e05aa257 select_priv:y insert_priv:y update_priv:y Delete_ Priv:y create_priv:y drop_priv:y reload_priv:y shutdown_priv:y process_priv:y
Ps:
from Mysql.user \g; 1. Row *************************** host:localhost user:root * 23ae809ddacaf96af0fd78ed04b6a265e05aa257 select_priv:y insert_priv:y update_priv:y Delete_ Priv:y create_priv:y drop_priv:y reload_priv:y shutdown_priv:y process_priv:y File_priv:y grant_priv:y references_priv:y index_priv:y alter_priv:y show_db_priv:y super_priv:y create_tmp_table_priv:y
Error:no query specified
Two Insert Table
Comparison of the two operations:
Create operation, table does not exist previously
mysql> CREATE TABLE t1 (x char), y char (+)) Select Host,user fromMysql.user; Query OK,Rows affected (0.57sec) Records:11duplicates:0 Warnings:0mysql> CREATE TABLE t2 (host char, user char ()) Select Host,user fromMysql.user; Query OK,Rows affected (0.58sec) Records:11duplicates:0 Warnings:0mysql>desc T1;+-------+----------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+----------+------+-----+---------+-------+| x | char (60) | YES | | NULL | || y | char (16) | YES | | NULL | || Host | char (60) | NO | | | || user | char (16) | NO | | | |+-------+----------+------+-----+---------+-------+4 rowsinchSet (0.01sec) MySQL>desc T2;+-------+----------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+----------+------+-----+---------+-------+| Host | char (60) | YES | | NULL | || user | char (16) | YES | | NULL | |+-------+----------+------+-----+---------+-------+2 rowsinchSet (0.01 sec)
mysql> CREATE TABLE t1 (id int, name char (10)); Query OK, 0 rows affected (0.30sec) MySQL> CREATE TABLE t2 (id int, name char (10)); Query OK, 0 rows affected (0.29sec) MySQL>Insert T2 Values(1,'Alex'), (2,'Egon'); Query OK,2 rows affected (0.29sec) Records:2duplicates:0 Warnings:0mysql>Insert T1 Values(1,'Wupeiqi'); Query OK,1 row affected (0.30sec) MySQL> Insert T1 Select id,name fromT2; Query OK,2 rows affected (0.32sec) Records:2duplicates:0 Warnings:0mysql> select * fromT1;+------+---------+| ID | Name |+------+---------+| 1 | Wupeiqi | | 1 | Alex | | 2 | Egon |+------+---------+3 rowsinchSet (0.00 sec)
Select as Usage
From onerows affected (0.57 duplicates:0 warnings:0mysqlfrom T1; +--------------+-----------+| Host Address | user name |+--------------+-----------+|% | Alex | |% | Egon | |% | egon1 | |% | Yuanhao | | % | Zuo | |% | zuo1 | | 127.0.0.1 | root | |:: 1 | root | | localhost | | | localhost | root | | localhost | zuo in Set (0.00 sec)
Insert action table previously exists
mysql> CREATE TABLE t1 (id int, name char (10)); Query OK, 0 rows affected (0.30sec) MySQL> CREATE TABLE t2 (id int, name char (10)); Query OK, 0 rows affected (0.29sec) MySQL>Insert T2 Values(1,'Alex'), (2,'Egon'); Query OK,2 rows affected (0.29sec) Records:2duplicates:0 Warnings:0mysql>Insert T1 Values(1,'Wupeiqi'); Query OK,1 row affected (0.30sec) MySQL> Insert T1 Select id,name fromT2; Query OK,2 rows affected (0.32sec) Records:2duplicates:0 Warnings:0mysql> select * fromT1;+------+---------+| ID | Name |+------+---------+| 1 | Wupeiqi | | 1 | Alex | | 2 | Egon |+------+---------+3 rowsinchSet (0.00 sec)
Database operation--query