在Ubuntu LAMP上安装数据库通常指安装MySQL或PostgreSQL,以下是具体步骤:
sudo apt update
sudo apt install mysql-server
安装过程中会提示设置root用户密码。sudo systemctl start mysql
sudo systemctl enable mysql
sudo mysql_secure_installation
按提示设置密码、删除匿名用户、禁用远程root登录等。CREATE DATABASE mydatabase;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo -i -u postgres
创建数据库和用户:CREATE DATABASE mydatabase;
CREATE USER myuser WITH PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
mysql -u root -p
输入密码后,执行SHOW DATABASES;
查看数据库列表。psql -d mydatabase -U myuser
输入密码后,执行\dt
查看表列表。sudo apt install php-mysql
sudo systemctl restart apache2
根据需求选择数据库类型,按步骤操作即可完成安装配置。