First how-to-do note
TyeYeah Lv4

This is the first note. It’s about how to use mysql in docker, how to use hexo to build blog and post it on Github using Pages.

First how-to-do note(mysql with docker、hexo)

Due to my project in college, I have to migrate the MYSQL 5.5 environment to MYSQL 8.0 version on my cloud hosting, but with a problem that I ccouldn’t start my mysql.service correctly ,I decided to deploy mysql with docker and learning basic docker using skills in the meantime.
By the way I have forgotten how to build my GitHub Pages with hexo, and this time I will give it a summary.

Basic Steps for MySQL Server Deployment with Docker

Basic Usage

first you need to install docker and test it (using root on debian)

1
2
3
4
5
$ apt update 
$ apt install docker # "wget -qO- https://get.docker.com/ | sh", to get the newest
$ apt install docker.io # turns out to be useful, while the one above does not...
$ systemctl start docker # or service docker start, to start service
$ docker run hello-world # docker-style hello-world to check your install

some usages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# show help
$ docker / docker xxx --help
# show images on localhost
$ docker images / docker image ls
# show running containers
$ docker ps [-a] / docker container ls
# search images xxx
$ docker search xxx
# get what you want
$ docker pull xxx

# if you have a specific target like me, only one step to get the image
$ docker run --name=mysqlxxx -p 33060:3306 -d mysql/mysql-server:tag
# '--name=mysqlxxx' means name it & call it by name, rather than by calling its long random id string
# '-d' means run it in the background
# '-p 33060:3306' to bind local port 33060 with docker's 3306 port
# notice:tag should be replaced with 5.5/5.6/5.7/8.0/8.0.x(x->latest)...

# Dockerfile usage
# to build your own docker image
# please search how to write Dockerfile, then
$ docker build -t xxx .
# '-t' to assign name of image
# the '.' at the tail indicate location of Dockerfile

#to delete
$ docker stop containerID
$ docker rm containerID
$ docker rmi imageID

About MYSQL

then we have a mysql docker, can be accessed by localhost:33060, but some configurations are needed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# this step is to see original password 
$ docker logs mysqlxxx 2>&1 | grep GENERATED # logs to see logs
# outputs like ↓
GENERATED ROOT PASSWORD: Axegh3kAJyDLaRuBemecis&EShOs

# login mysql first
$ docker exec -it mysqlxxx mysql -uroot -p
# '-it' usually combined to get interact with dockers, with commands follow
# 'mysql -uroot -p' is the example

# change password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
# or commands in docker shell
$ docker -it mysqlxxx /bin/bash
$ mysqladmin -uroot -p password newpassword

# then open remote connection permit
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';

Now we have a mysql docker which can be accessed remotely

GitHub Pages with Hexo

Using Hexo

Node.js is required, and Git is required on Windows

1
2
3
4
$ npm install hexo -g # use npm 
$ hexo init blogname # initial blog
$ cd blogname # enter blog directory
$ hexo server # start hexo as a server and you'll see hexo-style hello-world

directory structure

1
2
3
4
5
6
7
8
9
10
11
.
├── .deploy
├── public //to publish your html
├── scaffolds
├── scripts
├── source
| ├── _drafts
| └── _posts //md files to be generated as html
├── themes //themes' conf is _config.yml in this dir
├── _config.yml //blog's configure
└── package.json

common usages

1
2
3
4
$ hexo new passagename # create passagename.md in source/_posts/
$ hexo new page pagename # create pagename.html maybe
$ hexo generate # *.md are generated to be *.html
$ hexo deploy # deploy your blog on github

simplify:

hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy

combine:

$ hexo deploy -g
$ hexo server -g
$ hexo d -g
$ hexo s -g

GitHub Part

  1. first you need a github account

  2. then create a repository named : xxx.github.io (xxx => github username)

  3. configure your ssh public-key to login github without password (necessary for windows git)

  • configure git’s username & email (ensure your updates show on the wall)
    1
    2
    $ git config --global user.name "your GitHub username"
    $ git config --global user.email "your GitHub mailaddress"
  • check out whether you have public/private keys
    1
    2
    3
    4
    5
    $ cd ~/.ssh
    $ ls
    # things may look like ...
    authorized_keys2 id_rsa known_hosts
    config id_rsa.pub
  • if you can see xxx and xxx.pub, it means u got a keypair
  • if not, generate by yourself
    1
    2
    3
    $ ssh-keygen -t rsa -C "xx@xx.com"
    # '-t' have encryption method followed, and 'rsa' can be replaced
    # no need to bother other args
  • type some password once, and you have a keypair now
  • then paste strings in xxx.pub to : github index -> ur head portrait -> Settings -> SSH and GPG keys
    and now you can login github without typing password in ssh or git bash
  1. configure hexo
  • in _config.yml (xxx=>github username):
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # if only deploy to one repo
    deploy:
    type: git
    repo: git@github.com:xxx/xxx.github.io.git
    branch: master
    # deploy to two or more repos
    deploy:
    type: git
    repo:
    github: git@github.com:xxx/xxx.github.io.git
    gitlab: git@gitlab.com:xxx/xxx.gitlab.io.git
    branch: master
  • install plugin
    1
    2
    3
    $ npm install hexo-deployer-git --save
    # $ npm install hexo-generator-search --save
    $ npm install hexo-generator-searchdb --save # needed for my theme.
  • deploy blog on github
    1
    2
    3
    $ hexo deploy 
    # or
    $ hexo -d
  • sticky post
    1
    2
    3
    $ npm uninstall hexo-generator-index --save
    $ npm install hexo-generator-index-pin-top --save
    # add 'top: true' in 'Front-matter' to use it

    Notes for Markdown in Hexo

    Replace < >with &lt; &gt; //maybe not necessary

When using {something...}, add {% raw %} at the front and {% endraw %} as the tail,and finally it looks like {% raw %}{something...}{% endraw %}in your text to escape { and}
but in the code block sorrounded by three `, you can input whatever u want.

As for multiple tags in hexo articles writing, use tags:[tag1, tag2, …]

image hosting
https://sm.ms/
tables generator
http://www.tablesgenerator.com/

Powered by Hexo & Theme Keep
Total words 135.7k