IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> Mysql 使用过程问题总结 -> 正文阅读

[大数据]Mysql 使用过程问题总结

一、创建数据库

mysql> create database daily_test;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| daily_test         |
| information_schema |
| mysql              |
| performance_schema |
| pipeline           |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

create table if not exists internet_company (id INT UNSIGNED AUTO_INCREMENT,
                                             name VARCHAR(100) NOT NULL,
                                             person VARCHAR(100) NOT NULL,
                                             country VARCHAR(100) NOT NULL,
                                             PRIMARY KEY (id)
                                            )ENGINE=InnoDB DEFAULT CHARSET=utf8;

二、创建表

mysql> create table if not exists internet_company (id INT UNSIGNED AUTO_INCREMENT,
    ->                                              name VARCHAR(100) NOT NULL,
    ->                                              person VARCHAR(100) NOT NULL,
    ->                                              country VARCHAR(100) NOT NULL,
    ->                                              PRIMARY KEY (id)
    ->                                             )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show tables;
+----------------------+
| Tables_in_daily_test |
+----------------------+
| internet_company     |
+----------------------+
1 row in set (0.00 sec)

三、表中插入数据

mysql> insert into internet_company (id,name,person,country) values(1,"alibaba","mayun","china");
Query OK, 1 row affected (0.01 sec)

mysql> select * from internet_company;
+----+---------+--------+---------+
| id | name    | person | country |
+----+---------+--------+---------+
|  1 | alibaba | mayun  | china   |
+----+---------+--------+---------+
1 row in set (0.00 sec)


# id values可以加引号
mysql> insert into internet_company (id,name,person,country) values("2","jingdong","liuqiangdong","china");
Query OK, 1 row affected (0.01 sec)

mysql> select * from internet_company;
+----+----------+--------------+---------+
| id | name     | person       | country |
+----+----------+--------------+---------+
|  1 | alibaba  | mayun        | china   |
|  2 | jingdong | liuqiangdong | china   |
+----+----------+--------------+---------+
2 rows in set (0.00 sec)

# AUTO_INCREMENT id可以不设置,默认递增
mysql> insert into internet_company (name,person,country) values("wangyi","dinglei","china");
Query OK, 1 row affected (0.01 sec)

mysql> select * from internet_company;
+----+----------+--------------+---------+
| id | name     | person       | country |
+----+----------+--------------+---------+
|  1 | alibaba  | mayun        | china   |
|  2 | jingdong | liuqiangdong | china   |
|  3 | wangyi   | dinglei      | china   |
+----+----------+--------------+---------+
3 rows in set (0.00 sec)


# insert into 必须给所有的字段赋值
mysql> insert into internet_company (name,country) values("拼多多","china");
ERROR 1364 (HY000): Field 'person' doesn't have a default value


mysql> insert into internet_company (name,person,country) values("拼多多","","china");
Query OK, 1 row affected (0.00 sec)

mysql> select * from internet_company;
+----+-----------+--------------+---------+
| id | name      | person       | country |
+----+-----------+--------------+---------+
|  1 | alibaba   | mayun        | china   |
|  2 | jingdong  | liuqiangdong | china   |
|  3 | wangyi    | dinglei      | china   |
|  4 | 拼多多    |              | china   |
+----+-----------+--------------+---------+
4 rows in set (0.00 sec)


# 键值不对应,值中缺少person对应的
mysql> insert into internet_company (name,person,country) values("taobao","china");
ERROR 1136 (21S01): Column count doesn't match value count at row 1

mysql> insert into internet_company (name,person,country) values("taobao","戴""珊","china");
Query OK, 1 row affected (0.00 sec)

mysql> select * from internet_company;
+----+-----------+--------------+---------+
| id | name      | person       | country |
+----+-----------+--------------+---------+
|  1 | alibaba   | mayun        | china   |
|  2 | jingdong  | liuqiangdong | china   |
|  3 | wangyi    | dinglei      | china   |
|  4 | 拼多多    |              | china   |
|  5 | taobao    | 戴"珊        | china   |
+----+-----------+--------------+---------+
5 rows in set (0.00 sec)


四、更新表数据

mysql> update internet_company set person='黄铮,”帅哥“,‘哈哈’,说你呢' where id=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from internet_company;
+----+-----------+--------------------------------------------------+---------+
| id | name      | person                                           | country |
+----+-----------+--------------------------------------------------+---------+
|  1 | alibaba   | mayun                                            | china   |
|  2 | jingdong  | liuqiangdong                                     | china   |
|  3 | wangyi    | dinglei                                          | china   |
|  4 | 拼多多    | 黄铮,”帅哥“,‘哈哈’,说你呢                     | china   |
|  5 | taobao    | 戴"珊                                            | china   |
+----+-----------+--------------------------------------------------+---------+
5 rows in set (0.00 sec)


# 引号需要转义
mysql> update internet_company set person='戴珊 [[ $(time) == 'now' ]]' where id=5;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'now' ]]' where id=5' at line 1


mysql> update internet_company set person='戴珊 [[ $(time) == \'now\' ]]' where id=5;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from internet_company;
+----+-----------+--------------------------------------------------+---------+
| id | name      | person                                           | country |
+----+-----------+--------------------------------------------------+---------+
|  1 | alibaba   | mayun                                            | china   |
|  2 | jingdong  | liuqiangdong                                     | china   |
|  3 | wangyi    | dinglei                                          | china   |
|  4 | 拼多多    | 黄铮,”帅哥“,‘哈哈’,说你呢                     | china   |
|  5 | taobao    | 戴珊 [[ $(time) == 'now' ]]                      | china   |
+----+-----------+--------------------------------------------------+---------+
5 rows in set (0.00 sec)

五、参考文档:

1、https://blog.csdn.net/weixin_45126025/article/details/95970999

2、http://c.biancheng.net/view/2574.html

3、http://c.biancheng.net/view/2579.html

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-05-11 16:30:44  更:2022-05-11 16:32:13 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 22:59:22-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码