1.1. 基本操做
數據庫引擎html
Inodb:支持事務[原子性操做,完成一些列操做後纔算完成操做,不然rollback] mysql
MyISAM: 支持全文索引,強調了快速讀取操做,主要用於高負載的selectsql
建立數據庫,表:數據庫
show databases; # 查看當前Mysql都有那些數據,根目錄都有那些文件夾 create datab ase 數據庫名; # 建立文件夾 use 數據庫名; # 使用選中數據庫,進入目錄 show tables; # 查看當前數據庫下都有那些表 create table 表名(nid int, name varchar(20), pwd varchar(64)); # 建立數據庫表 select * from 表名; # 查看錶中的全部數據 insert into 表名(nid, name, pwd) values(1, 'alex', '123'); # 插入數據 select * from 表名 where id = 1;
用戶管理特殊命令:框架
建立用戶 create user '用戶名'@'IP地址' identified by '密碼'; create user 'hhh'@'192.168.25.%' identified by '777'; # 遠程鏈接 %表示通配符 刪除用戶 drop user '用戶名'@'IP地址'; 修改用戶 rename user'用戶名'@'IP地址' to '新用戶名'@'IP地址'; 修改密碼 set password for '用戶名' @ 'IP地址' = Password('新密碼') flush privileges; # 命令即時生效
權限管理:默認無ide
show grants for sh0731@localhost; # 查看權限 grant all privileges on mysql.test to ftl@localhost; # 受權 grant all privileges on mysql.user to hhh@'192.168.25.%';# 遠程受權 revoke all privileges on mysql.test from ftl@localhost; # 收權 flush privileges; # 命令即時生效
遠程鏈接:spa
mysql -u root -h 192.168.25.100 -P 3306 –p
數據庫級別操做:code
SHOW DATABASES; CREATE DATABASE 數據庫名稱; CREATE DATABASE 數據庫名稱 DEFAULT CHARSET utf8 COLLATE utf8_general_ci; USE 數據庫名稱; drop database 數據庫名稱;
表級別操做:htm
show tables; desc tb1; drop table hhh; # 刪除表 delete from hhh where id = 1; # 清空表內容 truncate table hhh; # 清空表,可是保留表的框架 select * from hhh; update hhh set sex = 'm' where id = 1; create table hhh ( id int, name varchar(12), sex varchar(2) )
忘記密碼:索引
# 啓動免受權服務端 mysqld --skip-grant-tables # 客戶端 mysql -u root -p # 修改用戶名密碼 update mysql.user set authentication_string=password('666') where user='root'; flush privileges;