貴陽手機(jī)網(wǎng)站制作全國免費發(fā)布廣告信息平臺
??不管是終端數(shù)據(jù)上報到服務(wù)器進(jìn)行存儲,還是客戶端的動態(tài)請求都需要用到數(shù)據(jù)庫,因此這里對數(shù)據(jù)庫的使用進(jìn)行了一些記錄,租用的是華為云的ECS彈性服務(wù)器(Ubuntu18)。下面以網(wǎng)頁登錄的賬號信息Acount為例。
一、Mysql的安裝
??首先需要進(jìn)行數(shù)據(jù)庫的安裝以及安全的設(shè)置:
sudo apt update
sudo apt install mysql-server
''' 數(shù)據(jù)庫安全設(shè)置'''
sudo mysql_secure_installation
二、創(chuàng)建數(shù)據(jù)庫和 Acount 表
(1)登錄Mysql
sudo mysql -u root -p
(2)創(chuàng)建數(shù)據(jù)庫和Acount表
#數(shù)據(jù)庫的創(chuàng)建
CREATE DATABASE my_database;
#使用數(shù)據(jù)庫
USE my_database;
#在數(shù)據(jù)庫中創(chuàng)建表,其中id為主鍵
CREATE TABLE Account (id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(255) NOT NULL,password VARCHAR(255) NOT NULL,role VARCHAR(50) NOT NULL
);
三、在Acount 表中插入數(shù)據(jù)
??插入的數(shù)據(jù)格式如下圖所示
??插入的數(shù)據(jù)代碼如下所示
INSERT INTO Account (username, password, role, email)
VALUES ('testuser', 'testpassword', 'admin', 'testuser@example.com');
四、查看Acount 表中數(shù)據(jù)
SELECT * FROM Account;
五、Acount 表中數(shù)據(jù)的刪除
??代碼如下所示,根據(jù)id來進(jìn)行數(shù)據(jù)庫數(shù)據(jù)的刪除
DELETE FROM Account WHERE id = 1;