下载 MySQL 8.0 官方仓库包

wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm

或者使用 curl

curl -O https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm

安装仓库包

sudo rpm -ivh mysql80-community-release-el7-7.noarch.rpm

导入所有可能的 MySQL GPG 密钥

sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

安装 MySQL 服务器

sudo yum install mysql-community-server

安装后:

1. 启动 MySQL/MariaDB

sudo systemctl start mysqld # MySQL

sudo systemctl start mariadb # MariaDB

2. 设置开机自启

sudo systemctl enable mysqld

sudo systemctl enable mariadb

3. 获取临时密码(仅 MySQL)

sudo grep 'temporary password' /var/log/mysqld.log

4. 安全配置

sudo mysql_secure_installation

用临时密码登录后修改密码:

1. 使用临时密码登录 MySQL

mysql -u root -p

输入临时密码

2. 设置新密码(MySQL 8.0)

ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword123!';

或者 MySQL 5.7

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('YourNewPassword123!');

3. 刷新权限

FLUSH PRIVILEGES;

1、下载protobuf编译器,并配置到环境变量中
https://github.com/protocolbuffers/protobuf/releases/download/v35.0/protoc-35.0-win64.zip

2、验证是否安装成功:
protoc --version

3、写proto测试文件test.proto:

syntax = "proto3";
package api;     // 指定默认包名

// 指定golang包名
option go_package = "./";

message Test {
  string msg = 1;
}

4、生成proto的go代码文件:
protoc --go_out=.\proto\api --go-grpc_out=.\proto\api test.proto (其中--go_out=<指定生成数据层代码路径> --go-grpc_out=<指定生成服务层代码路径>)

5、调用例子
服务端代码:

lis, err := net.Listen("tcp", "0.0.0.0:8002"))
if err != nil {
    log.Fatalf("failed to listen: %v", err)
}
// s := grpc.NewServer(grpc.Creds(insecure.NewCredentials()))
s := grpc.NewServer()
pb.RegisterApiServer(s, api.APIService)
pb.RegisterGreeterServer(s, api.NewTestApiService())
if err := s.Serve(lis); err != nil {
    log.Fatalf("failed to serve: %v", err)
}

func NewTestApiService() *testApiService {
return &testApiService{}
} 

type testApiService struct {
pb.UnimplementedGreeterServer
}

func (h *testApiService) SayHello(context context.Context, req *pb.HelloRequest) (*pb.HelloResponse,   error) {
log.Printf("Received: %v", req.Name)

return &pb.HelloResponse{
    Message:   fmt.Sprintf("Hello %s (age: %d)", req.Name, req.Age),
    Timestamp: time.Now().Format(time.RFC3339),
}, nil
}


客户端代码:

var conn *grpc.ClientConn
conn, err := grpc.Dial("localhost:8002",
    grpc.WithTransportCredentials(insecure.NewCredentials()),
    grpc.WithKeepaliveParams(keepalive.ClientParameters{
        Time: 5 * time.Second,
    }),
)
defer conn.Close()
if err != nil {
    fmt.Println("rpc连接错误", err.Error())
}

client := pb.NewGreeterClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

fmt.Println("已经链接rpc服务器成功")

resp, err := client.SayHello(ctx, &pb.HelloRequest{Name: "World", Age: 35})
if err != nil {
    fmt.Println("rpc测试请求报错", err.Error())
}
fmt.Println("rpc测试请求返回", resp)

log.Printf("Response: %s", resp.Message)









山之高,月出小。
月之小,何皎皎。
我有所思之人在远道,一日不见兮我心悄悄。

当你渴望未曾拥有的,不要忘了珍惜你现在拥有的,曾几何时,你现在拥有的,也是当初你梦寐以求的。