-- 修复数据库乱码问题

-- 1. 首先备份当前数据
CREATE TABLE IF NOT EXISTS user_backup_20260128 AS SELECT * FROM user;

-- 2. 修改数据库字符集为 utf8mb4
ALTER DATABASE peidu CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

-- 3. 修改 user 表字符集
ALTER TABLE user CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- 4. 如果数据已经是乱码，需要手动修复
-- 查看当前乱码的用户
SELECT id, username, real_name, phone FROM user WHERE id IN (1, 2);

-- 5. 手动更新用户数据（示例）
-- 请根据实际情况修改这些值
UPDATE user SET real_name = '张小明' WHERE id = 1 AND real_name LIKE '%�%';
UPDATE user SET real_name = '李四' WHERE id = 2 AND real_name LIKE '%�%';

-- 6. 验证修复结果
SELECT id, username, real_name, phone, role FROM user WHERE id IN (1, 2);
