MySQL是一款常用的關(guān)系型數(shù)據(jù)庫(kù)系統(tǒng),應(yīng)用廣泛。以下介紹MySQL數(shù)據(jù)庫(kù)系統(tǒng)的應(yīng)用。
1. 網(wǎng)站數(shù)據(jù)存儲(chǔ)
<?php
//連接數(shù)據(jù)庫(kù)
$mysqli = new mysqli("localhost", "user", "password", "dbname");
//添加數(shù)據(jù)
$mysqli->query("INSERT INTO table_name (column1, column2, column3)
VALUES (value1, value2, value3)");
//查詢(xún)數(shù)據(jù)
$result = $mysqli->query("SELECT * FROM table_name");
while ($row = $result->fetch_assoc()) {
echo $row["column1"] . " " . $row["column2"] . "<br>";
}
//關(guān)閉連接
$mysqli->close();
?>
2. 數(shù)據(jù)備份和恢復(fù)
//備份數(shù)據(jù)庫(kù)
mysqldump -u username -p password dbname >dbname_backup.sql
//恢復(fù)數(shù)據(jù)庫(kù)
mysql -u username -p password dbname< dbname_backup.sql
3. 數(shù)據(jù)庫(kù)管理
//創(chuàng)建數(shù)據(jù)庫(kù)
CREATE DATABASE dbname;
//刪除數(shù)據(jù)庫(kù)
DROP DATABASE dbname;
//創(chuàng)建表
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype
);
//刪除表
DROP TABLE table_name;
//添加列
ALTER TABLE table_name ADD column4 datatype;
//刪除列
ALTER TABLE table_name DROP column4;
以上介紹了MySQL數(shù)據(jù)庫(kù)系統(tǒng)的部分應(yīng)用,希望對(duì)大家有幫助。