MySQL是一個開源的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),在Web應用方面應用廣泛。本篇文章將介紹MySQL5.7的入門知識。
安裝MySQL5.7
sudo apt-get update sudo apt-get install mysql-server
啟動MySQL5.7服務
sudo systemctl start mysql
登錄MySQL5.7
sudo mysql -u root -p
創(chuàng)建數(shù)據(jù)庫
CREATE DATABASE dbname;
查看數(shù)據(jù)庫
SHOW DATABASES;
使用數(shù)據(jù)庫
USE dbname;
創(chuàng)建數(shù)據(jù)表
CREATE TABLE tablename ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
查看數(shù)據(jù)表
SHOW TABLES;
插入數(shù)據(jù)
INSERT INTO tablename (firstname, lastname, email) VALUES ('John', 'Doe', 'johndoe@example.com');
查詢數(shù)據(jù)
SELECT * FROM tablename;
更新數(shù)據(jù)
UPDATE tablename SET email='newemail@example.com' WHERE id=1;
刪除數(shù)據(jù)
DELETE FROM tablename WHERE id=1;
退出MySQL5.7
EXIT;