MYSQL用戶名:root MYSQL用戶名:root 3306 中文亂碼注意的地方: 1.先把有亂碼的表刪除掉 2.更改MYSQL的配置 (ini文件) 3.重啟MYSQL服務 1. 創建一個數據庫 create database 數據庫名; create database forStudy; 2. 使用已存在的數據庫 use 數據庫名; use forStudy; SQL語句 1. 建表語句 create table 表名( 字段 字段類型 ); create table student( id int primary key, name varchar(50), sex varchar(10), address varchar(255) ); create table student( user varchar(10), passwd varchar(50) ); //primary key 是用來定義主鍵(唯一標識) 刪除表語句 drop table 表名; drop table sudent; 2. 插入語句 insert into 表名(字段列表) values(對應字段值); INSERT INTO STUDENT (ID,NAME, SEX, ADDRESS) VALUES (3,'王五', '男','河南南陽'); INSERT INTO STUDENT (ID,NAME, SEX, ADDRESS) VALUES (4,'王丹', '女','河南南陽'); INSERT INTO STUDENT (ID,NAME, SEX, ADDRESS) VALUES (5,'劉六', '男','河南南陽'); 3.查詢語句 SELECT * FROM 表名; select * from student; 4. 更新語句 update 表名 set name = '李四' where id = 2; UPDATE STUDENT SET NAME = '李四' WHERE ID = 2; UPDATE STUDENT SET NAME = '李丹', SEX = '女' WHERE ID = 2; 5. 刪除語句 delete from 表名 where DELETE FROM STUDENT WHERE ID = 12; 增刪查改四種操作 student s_id s_name d_id 系別 d_id d_name 1 '軟件學院' select * from student where d_id = ( select d_id from dep where d_name = '軟件學院'); SQL