# Tips list

## git tips

git clone by ssh

```sh
    git clone ssh://git@192.168.2.166:3122/WFC/build.wfc.git
    git remote set-url origin git@192.168.2.166:3122/zhangsz/WFC/be.wfc.git
```

```sh
# 1. 生成 SSH ed25519密钥对
ssh-keygen -t ed25519 -C "simon@omc-dev-openEuler"
# 2. 复制公钥内容
cat ~/.ssh/id_ed25519.pub
# 3. 将公钥添加到 Gitee 
# 登录 Gitee -> 设置 -> SSH 公钥 -> 添加公钥
# 4. 测试连接
ssh -T git@192.168.2.166 -p 3122
```

## docker tips

使用 Docker 日志清理工具
你可以使用 Docker 提供的 docker system prune 命令来清理未使用的数据，包括日志文件：

```sh
    docker system prune -a
```

## java

安装 java 1.8

```sh
sudo apt update
sudo apt install openjdk-8-jdk
java -version
sudo update-alternatives --config java  # 选择当前默认的java版本
```

## mongodb

安装mongodb, omada sdn controller 和依赖

```sh
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update 
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
sudo dpkg -i omada_v5.15.6.7_linux_x64_20241128140044_1733188152890.deb 
sudo apt install --fix-broken 
```

## devices

ap sn: 22475N7000767 mac: B0-19-21-7E-27-40

omada link

curl --location --request POST 'https://aps1-omada-northbound.tplinkcloud.com/openapi/authorize/token?grant_type=client_credentials' \
--header 'Content-Language: en-US' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: aps1-omada-northbound.tplinkcloud.com' \
--header 'Connection: keep-alive' \
--data-raw '{
    "omadacId": "10ccde5bfee5142b28a07f6146f41056",
    "client_id": "48b3be2083dd4fbdb5f7cfd5c3a4abb6",
    "client_secret": "2556dfcafe6d4288b3f0921aa6391c76"
}'

curl --location --request POST 'https://192.168.2.249:8043/openapi/authorize/token?grant_type=client_credentials' \
--header 'Content-Language: en-US' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: 192.168.2.249:8043' \
--header 'Connection: keep-alive' \
--data-raw '{
    "omadacId": "f3aa6e479b94222581523710cc2c2a9d",
    "client_id": "5036e77c81a74008821c694a715fe2b8",
    "client_secret": "29faa06fb7f244b094377b48eb3083a7"
}'

## compile

mvn clean compile 
mvn clean package -P prod

## mysql/mariadb tips


有几种方法可以在 MariaDB 10.5 中修改 root 密码：

## 方法1：使用 mysql CLI（已登录）

如果你能以 root 用户登录 MariaDB：

```bash
sudo mysql -u root -p
```

然后执行以下命令：

```sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
```

## 方法2：安全模式重置（无法登录时）

1. 停止 MariaDB 服务：

```bash
sudo systemctl stop mariadb
```

2. 以跳过权限表的方式启动 MariaDB：

```bash
sudo mysqld_safe --skip-grant-tables --skip-networking &
```

3. 无需密码连接到 MariaDB：

```bash
sudo mysql
```

4. 设置新密码：

```sql
USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
EXIT;
```

5. 停止并正常重启 MariaDB 服务：

```bash
sudo pkill mysqld
sudo systemctl start mariadb
```

## 方法3：使用 mysql_secure_installation

这个工具可以帮助你重置 root 密码并优化一些安全设置：

```bash
sudo mysql_secure_installation
```

按照提示操作，其中会包括重置 root 密码的选项。

记得将示例中的 'new_password' 替换为你想要设置的实际密码。

simonzhangsz: ░░ The job identifier is 1143.
Apr 27 10:40:45 omc-dev-oe22 mariadb-prepare-db-dir[9062]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
Apr 27 10:40:45 omc-dev-oe22 mariadb-prepare-db-dir[9062]: If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.
Apr 27 10:41:15 omc-dev-oe22 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE

GitHub Copilot: # MariaDB Service Failure Analysis

Your MariaDB service is failing to start with an exit status of 1. The logs indicate:

1. The system believes the database is already initialized in mysql
2. There may be an issue with the database files or configuration

## Troubleshooting Steps

1. **Check MariaDB logs for more detailed error information:**

   ```bash
   sudo journalctl -u mariadb -n 50
   ```

   or

   ```bash
   sudo cat /var/log/mysql/error.log
   ```

2. **Check permissions on the data directory:**

   ```bash
   ls -la /var/lib/mysql
   ```

   Make sure the directory is owned by the mysql user:

   ```bash
   sudo chown -R mysql:mysql /var/lib/mysql
   ```

3. **Check disk space:**

   ```bash
   df -h
   ```

4. **Try safe start to see if it provides more diagnostics:**

   ```bash
   sudo mysqld_safe --skip-grant-tables
   ```

5. **Try repairing database files:**

   ```bash
   sudo mysqlcheck --all-databases --repair --use-frm
   ```

6. **Reset permissions and restart:**

   ```bash
   sudo chmod -R 755 /var/lib/mysql
   sudo chown -R mysql:mysql /var/lib/mysql
   sudo systemctl restart mariadb
   ```

If the database is corrupted, you might need to backup your data (if possible) and reinitialize:

```bash
sudo systemctl stop mariadb
sudo mv /var/lib/mysql /var/lib/mysql.bak
sudo mkdir /var/lib/mysql
sudo chown mysql:mysql /var/lib/mysql
sudo mysql_install_db --user=mysql
sudo systemctl start mariadb
```

After that, you would need to restore your databases from backup or recreate them.

simonzhangsz: 如何授权某些表的权限给用户

GitHub Copilot: # 如何授权某些表的权限给 MariaDB 用户

在 MariaDB 中，你可以为特定用户授予对某些表的权限。以下是完整的步骤：

## 1. 创建用户（如果尚不存在）

```sql
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
```

例如：
```sql
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
```

## 2. 授予表级权限

基本语法：
```sql
GRANT permission1, permission2, ... ON database_name.table_name TO 'username'@'host';
```

### 常见权限类型

- `SELECT` - 读取数据
- `INSERT` - 插入数据
- `UPDATE` - 更新数据
- `DELETE` - 删除数据
- `ALTER` - 修改表结构
- `CREATE` - 创建表
- `DROP` - 删除表
- `ALL PRIVILEGES` - 所有权限

### 实例

授予用户对特定表的SELECT权限：
```sql
GRANT SELECT ON mydb.mytable TO 'myuser'@'localhost';
```

授予用户对特定表的多个权限：
```sql
GRANT SELECT, INSERT, UPDATE ON mydb.mytable TO 'myuser'@'localhost';
```

授予用户对所有表的特定权限：
```sql
GRANT SELECT ON mydb.* TO 'myuser'@'localhost';
```

授予用户对多个表的权限：
```sql
GRANT SELECT ON mydb.table1 TO 'myuser'@'localhost';
GRANT INSERT ON mydb.table2 TO 'myuser'@'localhost';
```

## 3. 应用更改

授予权限后，刷新权限：
```sql
FLUSH PRIVILEGES;
```

## 4. 验证权限

查看用户权限：
```sql
SHOW GRANTS FOR 'myuser'@'localhost';
```

## 5. 撤销权限（如需）

```sql
REVOKE permission ON database_name.table_name FROM 'username'@'host';
```

例如：
```sql
REVOKE INSERT ON mydb.mytable FROM 'myuser'@'localhost';
```

确保在赋予权限时遵循最小权限原则，只给用户执行其工作所需的权限。