Create data sample on mysql & postgres docker image

Home   »   Create data sample on mysql & postgres docker image

- mysql docker: 
```
docker run --name mysql_demo -e MYSQL_ROOT_PASSWORD=root -v ~/workspace/data/mysql:/var/lib/mysql -d -p 3306:3306 mysql:8

docker exec -it mysql_demo mysql -uroot -proot

create database baihatviet;

use baihatviet;

create table song (
    id int primary key auto_increment,
    name varchar(1000),
    artist varchar(100),
    view_count int,
    created_at datetime default CURRENT_TIMESTAMP,
    updated_at datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

insert into song
    (name, artist, view_count)
values
    ('Lac Troi', 'Son Tung MTP', 100),
    ('Cho minh em', 'Binz', 100),
    ('Ta cu di cung nhau', 'Den Vau', 100);

select * from song;
```

- posgres docker: 

```
docker volume create --driver local --label example=posgres posgres-shared

docker run --name postgres_demo -e POSTGRES_PASSWORD=root -v postgres-shared:/var/lib/postgresql/data -p 5433:5432 -d postgres

docker exec -it postgres_demo psql -U postgres
create database baihatviet;
\c baihatviet;

create table song (
      id serial primary key ,
      name varchar(1000),
      artist varchar(100),
      view_count int,
      created_at timestamp default CURRENT_TIMESTAMP,
      updated_at timestamp default CURRENT_TIMESTAMP
);

insert into song
(name, artist, view_count)
values
('Lac Troi', 'Son Tung MTP', 100),
('Cho minh em', 'Binz', 100),
('Ta cu di cung nhau', 'Den Vau', 100);

select * from song;
```

Leave a Reply

Your email address will not be published. Required fields are marked *