在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
根據需求選擇數據庫類型,按步驟操作即可完成安裝配置。