澳门在线威尼斯官方 > 电脑数据库 > 增加和删除改查2018,MySQL基本概括操作01

原标题:增加和删除改查2018,MySQL基本概括操作01

浏览次数:139 时间:2019-09-17

MySQL基本回顾操作

学会了设置Docker,那么就将它选拔起来。(/滑稽脸)
事先想深造Mysql(Windows下陈设真辛苦),学会了Docker就方便了,直接利用Docker创造三个Mysql服务岂不美滋滋。创建容器的手续能够看一下分享04的Nginx的创始进度。
先是检查一下本地镜像。

[root@promote ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

没有Mysql的镜像,那么自个儿先来拉取多个Mysql镜像。
先物色一下Mysql的镜像。

[root@promote ~]# docker search mysql
INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql                                                  MySQL is a widely used, open-source relati...   6527      [OK]
docker.io   docker.io/mariadb                                                MariaDB is a community-developed fork of M...   2061      [OK]
docker.io   docker.io/mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   479                  [OK]
docker.io   docker.io/percona                                                Percona Server is a fork of the MySQL rela...   344       [OK]
docker.io   docker.io/zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       106                  [OK]
docker.io   docker.io/hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          89
docker.io   docker.io/centurylink/mysql                                      Image containing mysql. Optimized to be li...   60                   [OK]
docker.io   docker.io/zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server ...   58                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          36                   [OK]
docker.io   docker.io/tutum/mysql                                            Base docker image to run a MySQL database ...   32
docker.io   docker.io/centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   31
docker.io   docker.io/mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. ...   30
docker.io   docker.io/schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic back...   20                   [OK]
docker.io   docker.io/bitnami/mysql                                          Bitnami MySQL Docker Image                      15                   [OK]
docker.io   docker.io/zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        15                   [OK]
docker.io   docker.io/linuxserver/mysql                                      A Mysql container, brought to you by Linux...   14
docker.io   docker.io/centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   8
docker.io   docker.io/openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 ima...   6
docker.io   docker.io/circleci/mysql                                         MySQL is a widely used, open-source relati...   5
docker.io   docker.io/dsteinkopf/backup-all-mysql                            backup all DBs in a mysql server                4                    [OK]
docker.io   docker.io/mysql/mysql-router                                     MySQL Router provides transparent routing ...   2
docker.io   docker.io/openzipkin/zipkin-mysql                                Mirror of https://quay.io/repository/openz...   1
docker.io   docker.io/ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                    [OK]
docker.io   docker.io/cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0
docker.io   docker.io/cloudposse/mysql                                       Improved `mysql` service with support for ...   0                    [OK]

紧接着拉取镜像到本地,当然是开始的一段时期官方镜像。

[root@promote ~]# docker pull docker.io/mysql
Using default tag: latest
Trying to pull repository docker.io/library/mysql ...
latest: Pulling from docker.io/library/mysql
683abbb4ea60: Pull complete
0550d17aeefa: Pull complete
7e26605ddd77: Pull complete
9882737bd15f: Pull complete
999c06ab75f6: Pull complete
c71d695f9937: Pull complete
c38f847c1491: Pull complete
5e0cb05a8fc3: Pull complete
c89e3e373fca: Pull complete
fa39a2c9922d: Pull complete
b293d9c897c4: Pull complete
3dc061869740: Pull complete
Digest: sha256:43ed4f8c9d1695e97a39cdfe9475af9096e3723cfb79d820d8da00d61a277a85
Status: Downloaded newer image for docker.io/mysql:latest

拉取成功,今后始发创制Mysql容器。

[root@promote ~]# docker run -itd --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=000000 docker.io/mysql
30d60b852cf57c5f4e7df36846b10149387bb2b736cecb11f12a2d64a3bdbf43

跻身容器。

[root@promote ~]# docker exec -it mysql /bin/bash
root@30d60b852cf5:/#

连接数据库。

root@30d60b852cf5:/# mysql -uroot -p000000
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

连天数据库成功!
先读书查看数据库。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

下一场是创立数据库。

mysql> create database gubeiqing;
Query OK, 1 row affected (0.02 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| gubeiqing          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

随之使用自个儿正好创立好的gubeiqing数据库。

mysql> use gubeiqing;
Database changed

跻身那些数据库之后,来看一下有哪些表。

mysql> show tables;
Empty set (0.00 sec)

其不常候的数据表是空的,接着来创建数据表。

mysql> create table gubeiqing1(name varchar(20) not null , age varchar(20) not null);
Query OK, 0 rows affected (0.08 sec)

建表的通用语句语法是:CREATE TABLE table_name (column_name column_type);.
现行反革命来查阅一下数据表是什么样的。

mysql> desc gubeiqing1;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | NO   |     | NULL    |       |
| age   | varchar(20) | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

可以看看前日gubeiqing1本条数据表已经有了两列。可是还十分少,所以现在向那个数目表里增多数据。

mysql> insert into gubeiqing1 (name,age) values ('gbq',21);
Query OK, 1 row affected (0.04 sec)

假定加上的数据是字符型,那么必得使用单引号大概双引号。
当今询问一下以此表里全体的内容。

能够看看数据已经被大家加多进去了。

mysql> select * from gubeiqing1;
+------+-----+
| name | age |
+------+-----+
| gbq  | 21  |
+------+-----+
1 row in set (0.00 sec)

简言之的查询语句语法是:SELECT column_name,column_name FROM table_name

再来插入几条(插入时方可不点名列名,可是本身要理解插入数据的次第)。

mysql> insert into gubeiqing1 values ('zhangsan',20);
Query OK, 1 row affected (0.05 sec)

mysql> insert into gubeiqing1 values ('lisi',19);
Query OK, 1 row affected (0.03 sec)

翻看一下。

mysql> select * from gubeiqing1;
+----------+-----+
| name     | age |
+----------+-----+
| gbq      | 21  |
| zhangsan | 20  |
| lisi     | 19  |
+----------+-----+
3 rows in set (0.00 sec)

接下来学习改多少。
未来自己将lisiage字段,由19改为22

mysql> update gubeiqing1 set age=22 where name='lisi';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

改数据的主干回顾语法是:UPDATE table_name SET column_name1=values1,column_name2=values2 [WHERE 条件表达式]

再查看一下数据表。

mysql> select * from gubeiqing1;
+----------+-----+
| name     | age |
+----------+-----+
| gbq      | 21  |
| zhangsan | 20  |
| lisi     | 22  |
+----------+-----+
3 rows in set (0.00 sec)

能够看到lisiage字段已经被改了。
数据库基本的增加和删除改查,已经看了四个,接着来看删。
zhangsan那条数据从数额表中删除。

mysql> delete from gubeiqing1 where name='zhangsan';
Query OK, 1 row affected (0.39 sec)

mysql> select * from gubeiqing1;
+------+-----+
| name | age |
+------+-----+
| gbq  | 21  |
| lisi | 22  |
+------+-----+
2 rows in set (0.00 sec)

再来删除这几个表,最后删除库。

mysql> drop table gubeiqing1;
Query OK, 0 rows affected (0.13 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> drop database gubeiqing;
Query OK, 0 rows affected (0.09 sec)

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

UPDATE customers SET email='123@sina.com' where userid=10011;更新八个列UPDATE customers SET email='345@qq.com', name = '刘起' where userid=10012;

询问已插入的多寡 SELECTSELECT * FROM 表名;

表数据的询问WHERE 条件

改UPDATE 表 SET 字段名='修改过后的名字'where userid=10010;设置三个尺码能够找到那列消息 最佳通过主键的列来找查select * from 表名 where 条件;

1.数据库的技能发展2.相关概念 数据库;数据库系统;数据库管理连串; 为何选取mysql; SQL数据库语言3.哪些是mysql数据库? mysql的优势?是一款开源的即兴的软件 是一款多客商,多线程的SQL数据库服务器 能够神速,高效,安全的处理大批量数目,使用简便,易操作跨平台可移植型强,帮衬多样操作系统为五种编制程序语言提供了APT4.安装mysql,运转,链接,5.创设数据库 修改数据库 删除数据库6.数据库的存款和储蓄引擎和数据库的字段类型(数字,字符串,日期)7.数据库的创设,删除,修改创建表(字段,参数类型,为空,不为空,暗许值,主键,自增)查看数据库创设语句增多列CREATE TABLE 表名(id int not null,name char not null,age int not null deffault 0,primary key;查看表SHOW TABLSE;查看表详细音信SHOW CREATE TABLES 表名查看表结构SESC 数据表名;查看某一列的音信DESC 数据表名 列名使用NULL值使用主键primary key更新表ALTE中华V TABLE修改字段名ALTE福睿斯 TABLE 表名 CHANGE 字段名 新字段名 数据类型;删除列在MySQL的ALTER TABLE中,使用DROP col_name子句能够去除钦赐字段。下边将经过三个有血有肉实例演示如何删除字段。重命名表在MySQL的ALTER TABLE中,使用RENAME [AS] new_tbl_name子句能够修改表名。

将一个表里的数目插入到另贰个表中insert into 表selcet 列名,列名...from 表

本文由澳门在线威尼斯官方发布于电脑数据库,转载请注明出处:增加和删除改查2018,MySQL基本概括操作01

关键词:

上一篇:没有了

下一篇:没有了