Ubuntu环境下搭建数据库服务器,可选择MySQL或PostgreSQL,以下是具体步骤:
搭建MySQL数据库服务器
- 更新系统:
sudo apt update && sudo apt upgrade -y - 安装MySQL:
sudo apt install mysql-server -y - 启动并设置开机自启:
sudo systemctl start mysql,sudo systemctl enable mysql - 运行安全配置向导:
sudo mysql_secure_installation,按提示设置root密码等 - 验证安装:
sudo mysql -u root -p,输入密码登录 - 配置远程访问(可选):修改
/etc/mysql/mysql.conf.d/mysqld.cnf,将bind-address改为0.0.0.0,并重启服务
搭建PostgreSQL数据库服务器
- 更新系统:
sudo apt update && sudo apt upgrade -y - 安装PostgreSQL:
sudo apt install postgresql postgresql-contrib -y - 启动并设置开机自启:
sudo systemctl start postgresql,sudo systemctl enable postgresql - 配置用户和数据库:切换到
postgres用户,使用psql命令创建数据库和用户 - 配置远程访问(可选):编辑
/etc/postgresql/和/main/postgresql.conf pg_hba.conf,修改相关配置并重启服务