Debian 12 (Bookworm) 安装 MySQL 8.0
1. 添加 MySQL 官方仓库
Section titled “1. 添加 MySQL 官方仓库”wget https://dev.mysql.com/get/mysql-apt-config_0.8.32-1_all.deb -O /tmp/mysql-apt-config.debsudo dpkg -i /tmp/mysql-apt-config.deb安装时弹出界面选择 MySQL 8.0,然后选 OK。
2. 修复 GPG 密钥过期问题
Section titled “2. 修复 GPG 密钥过期问题”sudo sed -i 's|signed-by=/usr/share/keyrings/mysql-apt-config.gpg|trusted=yes|g' /etc/apt/sources.list.d/mysql.list3. 安装 MySQL Server
Section titled “3. 安装 MySQL Server”sudo apt updatesudo apt install -y mysql-server安装过程中会提示设置 root 密码。
4. 开机自启
Section titled “4. 开机自启”sudo systemctl enable mysqlsudo systemctl start mysql验证状态:
sudo systemctl status mysql5. 配置远程连接
Section titled “5. 配置远程连接”5.1 修改绑定地址
Section titled “5.1 修改绑定地址”sudo sed -i 's/^bind-address\s*=.*/bind-address = 0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf如果文件不存在,检查:
grep -r "bind-address" /etc/mysql/找到对应文件修改即可。
5.2 放行 root 远程登录
Section titled “5.2 放行 root 远程登录”mysql -u root -pCREATE USER 'root'@'%' IDENTIFIED BY '你的root密码';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;FLUSH PRIVILEGES;EXIT;如已有
root@'%',可改为:ALTER USER 'root'@'%' IDENTIFIED BY '你的root密码';FLUSH PRIVILEGES;
5.3 创建普通远程用户
Section titled “5.3 创建普通远程用户”mysql -u root -pCREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password';GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'%' WITH GRANT OPTION;FLUSH PRIVILEGES;EXIT;如需限制来源 IP,将
%替换为具体 IP,如'your_user'@'192.168.1.100'。
5.4 重启生效
Section titled “5.4 重启生效”sudo systemctl restart mysql5.5 防火墙放行(如有)
Section titled “5.5 防火墙放行(如有)”sudo ufw allow 3306/tcp本地验证:
mysql -u root -p -e "SELECT VERSION();"远程验证(从其他机器):
mysql -h <服务器IP> -u your_user -p© 2025-2026 LiuXing. All Rights Reserved.