在命令行在操做數據庫:(注意 加了 ; 是SQL語句結束標識 )php
(1)鏈接數據庫: mysql -h localhost(主機地址) -u root(用戶名) -p 回車 在輸入數據庫密碼mysql
(2)修改密碼:mysqladmin -u root(用戶名) -p 123456(舊密碼) password 12345(新密碼);linux
(3)顯示數據庫列表: show databases;sql
(4)顯示某個數據庫中的數據表: use test(數據庫名稱); show tables;thinkphp
(5)顯示數據表的結構: describe user(表名);數據庫
(6)建立數據庫: create database thinkphp(數據庫名);spa
(7)刪除數據庫: drop database thinkphp(數據庫名);命令行
(8)建立表:use thinkphp(數據庫名); create table user(表名)排序
( id int(3) auto_increment(自動增加) not null primary key(設置爲主鍵),索引
name varchar(10) not null,
age int(3) not null ) engine = myisam partition by key(id) partition 5 ;
注意分區:key hash 是去餘操做 list rang 是條件分區 list條件是可列舉的 rang條件是能夠範圍的。
(9) 刪除表:drop table user(表名);
(10) 向表中插入數據: insert into user(表名) values ( 1 , `php`, 1);
(11) 刪除表中的數據: delete from user(表名) where age =3;
(12) 顯示錶中的數據: select * from user(表名);
(13) 清空表中的數據: delete from user(表名) ;
(14) 更新表中的數據: update user(表名) set name = 'linux' where id =2;
(15) 查詢表中結果排序: select * from user order by id desc(倒序排列 ase順序排列);
(16)查詢表中某個數據的總數: select count(id) from user where name = 'linux';//id、name 字段名
(17)查詢表中的最大值: select max(id) from user; //sum 求和 avg 平均數 min 最小數 max 最大數
(18)組合查詢: select goods.id goods.name user.age from goods, user where goods.id = user.id;
(19)創建索引: create index user_index(索引表名字任意取) on user(id);
(20)鏈接查詢: select goods.id goods.name user.age from goods inner join user on goods.id = user.id order by goods.name; //inner join 是查找兩我的相等的數據 left join 查找左表中全部的數據右表中相等的數據
right join 查找右表中的全部數據左表中想等的數據
(21)向表中添加字段: alter table user(表名) add sex bool(要添加的字段名和類型);
(22)向數據庫中導入sql文件:先定位到數據庫中在使用 source d:thinkphp.sql
(23) 退出數據庫: exit;