1.MySQL安装
bash
# 系统环境:Win11的WSL
# 1.安装mysql相关模块
>> sudo apt-get install mysql-server -y
>> sudo apt-get install libmysqlclient-dev -y
2.MySQL配置
bash
# 1.进入mysql
>> sudo mysql
# 2.进入mysql数据库
mysql> use mysql;
# 3.修改root用户密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
# 4.修改远程访问
mysql> UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
mysql> flush privileges;
mysql> exit;
# 5.创建数据库
mysql> create database webdb;
# 6.给创建的数据库创建表
mysql> use webdb;
mysql> create table user(
username char(50) NULL,
passwd char(50) NULL
) engine=InnoDB;
# 7.创建用户
mysql> create user 'mirror'@'localhost' identified by 'cjy';
# 8.给用户mirror表访问权限
mysql> grant all on webdb.user to 'mirror'@'localhost';
# 9.刷新系统权限,即时生效
mysql> flush privileges;
3.源码下载
bash
>> git clone https://github.com/qinguoyi/TinyWebServer.git
4.修改main.cpp
文件中user, passwd, databasename三个选项:
C++
string user = "mirror";
string passwd = "cjy";
string databasename = "webdb";
5.编译运行TinyWebServer
项目
bash
>> chmod +x build.sh && ./build.sh && ./server
6.运行结果查询
bash
# 浏览器运行
localhost:9006