Ubuntu下PhpStorm数据库连接教程
在开始配置前,需确保以下条件已满足:
sudo apt install mysql-server)、PostgreSQL(sudo apt install postgresql postgresql-contrib)等;mysql-client(sudo apt install mysql-client),连接PostgreSQL需安装postgresql-client(sudo apt install postgresql-client);ufw allow 3306(MySQL)或ufw allow 5432(PostgreSQL)开放端口。启动PhpStorm后,通过以下方式打开数据库面板:
在数据库面板右上角点击**+**图标,选择要连接的数据库类型(如MySQL、PostgreSQL、SQLite等)。
在弹出的“Data Source Properties”窗口中,填写以下关键信息:
localhost,远程数据库填IP或域名);3306,PostgreSQL默认5432);root或自定义用户);填写完成后,点击Test Connection按钮。若弹出绿色提示“Connection successful”,说明配置正确;若失败,需检查:
sudo systemctl status mysql);/etc/mysql/mysql.conf.d/mysqld.cnf中的bind-address为0.0.0.0,并授权用户远程访问)。测试通过后,点击OK保存配置。此时,数据库面板将显示已连接的数据库,可展开节点浏览表、视图、存储过程等对象,右键点击表可选择New → Query Console打开SQL控制台,编写并执行查询语句。
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password';);/etc/postgresql/<version>/main/pg_hba.conf文件,添加host all all 0.0.0.0/0 md5以允许远程连接;