Mysql

mysql> show variables like 'wait_timeout'; #查询连接超时
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)


mysql> show processlist; # 查询连接表
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+----------+------------------+
| 7 | root | localhost | NULL | Sleep | 2140 | | NULL |
| 9 | root | localhost | NULL | Sleep | 773 | | NULL |
| 10 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+
3 rows in set (0.00 sec)

mysql> show variables like 'query_cache_type'; # 查询缓存
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| query_cache_type | OFF |
+------------------+-------+
1 row in set (0.00 sec)

— 语法基础

mysql> create database `create_news`; # 创建数据库
Query OK, 1 row affected (0.00 sec)

mysql> use `create_news `; # 进入数据库
Database changed

mysql> show databases; # 查询数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| create_news |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

mysql> use create_news; # 进入数据库

Database changed

mysql> show tables; # 显示所有表
+-----------------------+
| Tables_in_create_news |
+-----------------------+
| news |
| news01 |
| news02 |
+-----------------------+
3 rows in set (0.00 sec)

mysql> desc news; # 显示表所有字段信息
+------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(200) | NO | | NULL | |
| content | varchar(2000) | NO | | NULL | |
| created_at | datetime | YES | | NULL | |
| types | varchar(10) | NO | | NULL | |
| images | varchar(300) | NO | | NULL | |
| autors | varchar(20) | NO | | NULL | |
| view_count | int(11) | YES | | 0 | |
| is_valid | smallint(6) | YES | | 1 | |
+------------+---------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)


# 添加数据。语法 INSERT INTO table_name(字段) VALUES(值) (ps NOW()表示当前创建时间)
mysql> INSERT INTO news (
-> title,content,created_at,types,images,autors)
-> VALUES(
-> '天天Python','我要学习',NOW(),'新闻','not photo','lianwu');
Query OK, 1 row affected (0.00 sec)


# 查询数据。 语法 SELECT * form table_name WHERE 添加。 (ps *表示所有字段 WHERE条件不设置表示显示所有信息列表)

mysql> SELECT * from news WHERE id >20;
+----+--------------+--------------+---------------------+--------+-----------+--------+------------+----------+
| id | title | content | created_at | types | images | autors | view_count | is_valid |
+----+--------------+--------------+---------------------+--------+-----------+--------+------------+----------+
| 29 | 天天Python | 我要学习 | 2020-08-23 20:59:39 | 新闻 | not photo | lianwu | 0 | 1 |
| 30 | 天天Python | 我要学习 | 2020-08-23 21:00:00 | 新闻 | not photo | lianwu | 0 | 1 |
+----+--------------+--------------+---------------------+--------+-----------+--------+------------+----------+
2 rows in set (0.00 sec)

原文地址:https://www.cnblogs.com/donglian1/p/13550746.html