[TOC] #### 1. 本地数据库 --- **新建一个 MySQL 连接** ![](https://img.itqaq.com/art/content/104997991895e907bb3c926fce2eb617.png) **直接输入连接名、MySQL用户名和密码就行** ![](https://img.itqaq.com/art/content/fc51c996aaab38839c0d97ce2875059e.png) #### 2. 服务器端数据库 --- 情景假设:服务器上安装宝塔面板,在宝塔面板中创建的 MySQL 数据库 **一. 服务器运行商安全组放开 3306 端口** ![](https://img.itqaq.com/art/content/7997a74ab86c8d1968fcb8492fe02afc.png) **二. 宝塔面板防火墙放开 3306 端口** ![](https://img.itqaq.com/art/content/e9ce3cf3e07faf2075721a3d21f3498a.png) **三. 放开数据库权限** ![](https://img.itqaq.com/art/content/aeec8c275450a0ac3b77cf128b59a75a.png) **四. 连接参数** | 参数项 | 参数值 | | ------------ | ------------ | | 主机 | 服务器公网 IP | | 端口 | MySQL 端口 | | 用户名、密码 | MySQL 用户名密码 | ![](https://img.itqaq.com/art/content/cb1486f762818869a978e4cd52773516.png) #### 3. 云服务器数据库(腾讯云) --- 微擎 config.php | 参数项 | 参数值 | | ------------ | ------------ | | host | gz-cdb-9v361hm1.sql.tencentcdb.com:62104 | | username | wx_dianduxxx | | password | qq7801xxx | | port | 3306 | **一、ping 云数据库服务器域名,获得服务器 IP** ![](https://img.itqaq.com/art/content/91e0587815663cbc3cd9b7b47e1b89d0.png) **二、创建腾讯云云数据库连接** ![](https://img.itqaq.com/art/content/430a8b4a39644aecfee2696c6e12a663.png) **三、输入连接参数,测试连接** ![](https://img.itqaq.com/art/content/2a2cf4d6ec5137b3bc4d6d222b28a30c.png)