Skip to content

Commit

Permalink
Add init SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
youweics committed Mar 14, 2019
1 parent 2d64b0c commit 0b4fad2
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 5 deletions.
Empty file removed docker
Empty file.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ services:
- "MYSQL_DATABASE=testbugucms"
- "MYSQL_USER=test"
- "MYSQL_PASSWORD=123456"
# 可以加--default-time-zone='+8:00'设定时区
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
volumes:
- ./data/mysql/db:/var/db
- ./jvue-docker/jvue-mysql/my.cnf:/etc/my.cnf
- ./data/mysql/log:/var/log
- ./jvue-docker/jvue-mysql/init:/docker-entrypoint-initdb.d/
restart: always
108 changes: 108 additions & 0 deletions jvue-docker/jvue-mysql/init/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# 数据库已经配置,这里不指定
-- DROP DATABASE IF EXISTS testbugucms;
-- CREATE DATABASE testbugucms CHARACTER SET utf8 COLLATE utf8_general_ci;
USE testbugucms;

# 用户已经指定,不要创建
-- CREATE USER 'test'@'%' IDENTIFIED BY '123456';
-- GRANT All privileges ON *.* TO '123456'@'%';

CREATE TABLE users (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
username VARCHAR(45) NOT NULL UNIQUE,
password_md5 VARCHAR(45) NOT NULL,
email VARCHAR(45),
screen_name VARCHAR(45),
created TIMESTAMP NOT NULL DEFAULT current_timestamp,
logged TIMESTAMP NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE articles (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT current_timestamp,
modified TIMESTAMP NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp,
content TEXT,
author_id INT,
hits INT DEFAULT 0 NOT NULL,
tags VARCHAR(255),
category VARCHAR(255),
status VARCHAR(32),
type VARCHAR(32),
allow_comment BOOLEAN DEFAULT TRUE NOT NULL,
comment_count INT DEFAULT 0 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE comments (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
article_id INT NOT NULL,
p_id INT,
content TEXT NOT NULL,
name VARCHAR(255),
email VARCHAR(255),
website VARCHAR(255),
agree INT NOT NULL DEFAULT 0,
disagree INT NOT NULL DEFAULT 0,
ip VARCHAR(255),
agent VARCHAR(255),
created TIMESTAMP NOT NULL DEFAULT current_timestamp
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE metas (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
type VARCHAR(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE middles (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
a_id INT NOT NULL,
m_id INT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE logs (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
action VARCHAR(255),
data TEXT,
message VARCHAR(255),
type VARCHAR(255),
ip VARCHAR(255),
user_id INT,
created TIMESTAMP NOT NULL DEFAULT current_timestamp
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


INSERT INTO users (username, password_md5, email, screen_name)
VALUES ('jvue', '3e6693e83d186225b85b09e71c974d2d', '', 'admin');

INSERT INTO articles (title, created, modified, content, author_id, hits, tags, category, status, type)
VALUES ('Hello world', now(), now(), '
欢迎使用[Jvue](https://github.com/zzzzbw/Jvue)! 这是你的第一篇博客。快点来写点什么吧
```java
public static void main(String[] args){
System.out.println("Hello world");
}
```
> 想要了解更多详细信息,可以查看[文档](https://github.com/terwer/jvue)。', 1, 0, 'First', 'New', 'publish', 'post');

INSERT INTO comments (article_id, content, name, email, website, agree, disagree, ip, agent) VALUES ('1', '## 测试评论
这是我的网址[jvue](http://www.terwergreen.com)', 'terwer', '920049380@qq.com', 'http://www.terwergreen.com', '1', '0', '0.0.0.1', '');

INSERT INTO metas (name, type) VALUES ('First', 'tag');
INSERT INTO metas (name, type) VALUES ('New', 'category');

INSERT INTO middles (a_id, m_id) VALUES (1, 1);
INSERT INTO middles (a_id, m_id) VALUES (1, 2);

INSERT INTO articles (title, created, modified, content, author_id, tags, category, status, type)
VALUES ('About', now(), now(), '# About me
### Hello word
这是关于我的页面
* [Github](https://github.com/terwer)
* [知乎](https://www.zhihu.com/people/terwer)
### 也可以设置别的页面
* 比如友链页面', 1, NULL, NULL, 'publish', 'page');
13 changes: 10 additions & 3 deletions jvue-docker/jvue-mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

[mysqld]
#
Expand Down Expand Up @@ -30,6 +34,9 @@ symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# set encode to utf8mb4
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
# custom
default-storage-engine=INNODB
character-set-server=utf8
init_connect='SET NAMES utf8'


0 comments on commit 0b4fad2

Please sign in to comment.