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 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> 【postgres和mysql】基于docker搭建以及phppgadmin和phpmyadmin的应用(个人备份用非教程) -> 正文阅读

[大数据]【postgres和mysql】基于docker搭建以及phppgadmin和phpmyadmin的应用(个人备份用非教程)

postgres

1、docker-compose文件

# Specify the version for docker-compose.yml
version: "3.8"

# add the serivces needed (postgres,phppgadmin)
services:
  postgres:
    container_name: postgres
    image: postgres:latest
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: mypassword
      # Optional: Give a name to the database, otherwise
      # use the default value POSTGRES_USER as a database name (user in this case.)
      # POSTGRES_DB: testdb
    ports:
      - "5432:5432"
    volumes:
      - dbdata:/var/lib/postgresql/data

  phppgadmin:
    container_name: phppgadmin
    image: neimheadh/phppgadmin:latest
    ports:
      - "8080:80" # web browsers block the port 100080. Use 8080 instead.
    environment:
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
      - POSTGRES_USER=user
      - POSTGRES_PASS=mypassword

volumes:
  dbdata:

2、Running the containers

docker-compose up -d

3、Enter iterative mode

docker exec -it postgres psql -U user

4、Some useful commands

# show tables from current schema
\dt
# list tables from all schemas
\dt *.*
# show table
\d TABLE_NAME
# show databases
\l

5、Create table and insert content

CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT NULL, NAME text);
INSERT INTO company(id,name) values (1,'test');
SELECT * from company;

6、Go to phpPgAdmin

http://localhost:8080/

7、Go back to terminal. Simple SQL queries

# NOTE: when doing queries, uncheck the paginate results
# create a new db
create database employee_database;
# create table
create table employee (
 last_name varchar(150),
 department_id int,
 primary key (last_name)
);
# insert content
insert into employee (last_name, department_id) values
('Rafferty', 31),
('Jones', 33),
('Steinberg', 33),
('Robinson', 34),
('Smith', 34);
# creat another table
create table department (
 department_id int,
 department_name varchar(150),
 primary key ( department_name )
);
# insert content
insert into department (department_id, department_name) values
(31, 'Sales'),
(33, 'Engineering'),
(34, 'Clerical'),
(35, 'Marketing');
# visualizing tables
select *
from employee;
select *
from department;
# single relation query
select department_name
from department dept
where dept.department_id = 33;
# join, (must specify ON in postgres)
# select * from employee emp join department dept
select * from employee emp join department dept ON true
# join with filtering
select *
from employee emp join department dept
on emp.department_id=dept.department_id
# delete (rows)
delete from employee
where last_name='Jones';
# update
update employee
set department_id=37
where last_name = 'Robinson';
# alter table command, add column, drop column
alter table employee
add salary real null;
update employee
set salary = 5000
where department_id = 33;
update employee
set salary = 6000
where department_id = 31;
update employee
set salary = 7000
where department_id = 34;
# Useful arithmetic functions
select avg(salary)
from employee;
# drop column
alter table employee
drop column department_id;

8、Shutdown

docker-compose down

mysql

1、docker-compose文件

version: "3.8"

services: # adds 2 services: mysql and phpmyadmin to connect with
  db:
    image: mysql:latest # use latest version of mysql
    container_name: db # add a name for the container
    command: --default-authentication-plugin=mysql_native_password
    restart: unless-stopped
    environment: # add default values, see docs for more info.
      MYSQL_USER: user
      MYSQL_ROOT_PASSWORD: mypassword
      MYSQL_PASSWORD: mypassword
      MYSQL_DATABASE: testdb # create this database on startup
    volumes:
      - my-db:/var/lib/mysql
    ports:
      - '3306:3306'
  
  phpmyadmin:
    container_name: phpmyadmin
    image: phpmyadmin/phpmyadmin:latest
    ports:
     - "8082:80"
    environment:
      MYSQL_ROOT_PASSWORD:  #(Required) set the password for the root superuser account.
      PMA_HOST: db   # define the address/hostname of the mysql server eg mysql container name.
      PMA_USER: root # this is the root user to login on startup
      PMA_PASSWORD: mypassword # use the root password to login on startup.

volumes: # add persistent data even if container is removed.
  my-db:

2、Go to phpMyAdmin

http://localhost:8082/

3、Create database and the schema

CREATE DATABASE freedbtech_language

CREATE TABLE programming_languages
(
 id INT(11) NOT NULL auto_increment ,
 name VARCHAR(255) NOT NULL ,
 released_year INT NULL ,
 githut_rank INT NULL ,
 pypl_rank INT NULL ,
 tiobe_rank INT NULL ,
 created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 updated_at DATETIME on UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT 
CURRENT_TIMESTAMP ,
 PRIMARY KEY (id),
 UNIQUE idx_name_unique (name(255))
)
engine = innodb charset=utf8mb4 COLLATE utf8mb4_general_ci;

4、Insert some data into the table

INSERT INTO 
programming_languages(id,name,released_year,githut_rank,pypl_rank,tiobe_rank) 
VALUES 
(1,'JavaScript',1995,1,3,7),
(2,'Python',1991,2,1,3),
(3,'Java',1995,3,2,2),
(4,'TypeScript',2012,7,10,42),
(5,'C#',2000,9,4,5),
(6,'PHP',1995,8,6,8),
(7,'C++',1985,5,5,4),
(8,'C',1972,10,5,1),
(9,'Ruby',1995,6,15,15),
(10,'R',1993,33,7,9),
(11,'Objective-C',1984,18,8,18),
(12,'Swift',2015,16,9,13),
(13,'Kotlin',2011,15,12,40),
(14,'Go',2009,4,13,14),
(15,'Rust',2010,14,16,26),
(16,'Scala',2004,11,17,34);
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-10-17 12:41:07  更:2022-10-17 12:45:03 
 
开发: 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/15 15:28:32-

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