0%

连接虚拟机的docker启动的mysql镜像

整体关系图
guanxi

mysql

1、下载mysql镜像

ubuntu下需要root权限

1
docker pull mysql:5.7

2、启动镜像

1
docker run --name=mysql -it -p 3396:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
-it:交互式
-p:自定义端口(宿主机端口:容器内启动的端口)
每个容器启动之后相当于一个系统
-e:设置
-d:后台挂载
–name:容器启动后的名字

3、进入mysql镜像

查看启动之后镜像的id

1
docker ps

img
如图👆

进入容器

1
docker exec -it dd3be6ee5104 /bin/bash

启动进入mysql

1
2
docker exec -it dd3be6ee5104 /bin/bash
mysql -uroot -p

设置所有地址可用root用户进入

1
2
3
update user set host = '%' where user = 'root';
grant all on *.* to admin@'%' identified by 'root' with grant option;
flush privileges; 刷新权限

检查是否设置成功

1
select host,user,plugin,authentication_string from mysql.user;

如图
mysql
mysql8.0以上需要将plugin的caching_sha2_password设置为my_native_password,
这里我们用的是mysql5.7所以不用设置
mysql设置结束

4、查看是否能ping通虚拟机

查看虚拟机ip(enss33网卡上的ip)

1
ifconfig

mysql
红色部分(即192.168.127.129)

回到主机(win10)打开cmd

1
ping 192.168.127.129

mysql
正常能ping通即可,如果不行就关闭虚拟机的防火墙

5、使用图形化工具连接mysql(navicat为例)

img.png
img.png

md5加密(用于密码加密)

md5加密简介

MD5消息摘要算法,属Hash算法一类。MD5算法对输入任意长度的消息进行运行,产生一个128位的消息摘要(32位的数字字母混合码)。
加密不可逆可以用于密码加密

java工具类

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
30
31
32
33
34
import org.springframework.stereotype.Service;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
public String code(String str) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte[] byteDigest = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < byteDigest.length; offset++) {
i = byteDigest[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
//32位加密(小写)
return buf.toString();
//32位加密(大写)
//return buf.toString().toUpperCase();
// 16位的加密(小写)
//return buf.toString().substring(8, 24);
// 16位的加密(大写)
//return buf.toString().substring(8, 24).toUpperCase();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}

}

md5加密代码

1
String password = md5Utils.code("要加密的字符串");

与数据库密码比对

1
user1.getPassword().equals(md5Utils.code(param.getString("password")));

base64编码

base64简介

Base64是一种基于64个字符的编码算法,根据RFC 2045的定义:“Base64内容传送编码是以一种任意8位字节序列组合的描述形式,这种形式不易被人直接识别”。base64是一种编码方式,不是加密方法

工具类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import org.springframework.util.Base64Utils;

/**
* @Author 87312
*/
public class Base64Util {

public static byte[] decryptBASE64(byte[] key) throws Exception {
return Base64Utils.decode(key);
}
public static String encryptBASE64(byte[] key) throws Exception {
return new String(Base64Utils.encode(key));
}
}

base64简单使用

1
2
jiami = Base64Util.encryptBASE64("字符串".getBytes());
String jiemi = new String(Base64Util.decryptBASE64(jiami.getBytes()), "UTF-8");

github默认主分支是main,gitee默认是master

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment