mysql -u root -h?192.168.1.1?-p
1.基本操作
show databases;??????????????? # 查看當(dāng)前Mysql都有那些數(shù)據(jù),根目錄都有那些文件夾
create database 數(shù)據(jù)庫(kù)名;?? # 創(chuàng)建數(shù)據(jù)庫(kù)文件夾
create table tb5(
? ???? nid int not null auto_increment primary key,
? ???? name varchar(16),
? ???? age int default 19
? )engine=innodb default charset=utf8;
use 數(shù)據(jù)庫(kù)名;?????????????? # 使用選中數(shù)據(jù)庫(kù),進(jìn)入目錄
show tables;??????????????? # 查看當(dāng)前數(shù)據(jù)庫(kù)下都有那些表,
create table 表名(nid int,name varchar(20), pwd varchar(64)); # 創(chuàng)建數(shù)據(jù)庫(kù)表
drop table 表名????????????????? # 刪除整個(gè)表
delete from 表名?????????????? # 刪除表中的數(shù)據(jù),保留表結(jié)構(gòu),可恢復(fù)
truncae table 表名????????? # 以更快的方式刪除表中的數(shù)據(jù),不可恢復(fù)
desc 表名? ? ? ? ? ? ? ? ? ? ?#查看描述
select * from 表名;?????? # 查看表中的所有數(shù)據(jù)
insert into 表名(nid,name,pwd) values(1,'alex','123');? # 插入數(shù)據(jù)
2. 用戶(hù)管理
創(chuàng)建用戶(hù)
create user '用戶(hù)名'@'IP地址' identified by '密碼';
刪除用戶(hù)
drop user '用戶(hù)名'@'IP地址';
修改用戶(hù)
rename user '用戶(hù)名'@'IP地址'; to '新用戶(hù)名'@'IP地址';;
修改密碼
set password for '用戶(hù)名'@'IP地址' = Password('新密碼')
PS:用戶(hù)權(quán)限相關(guān)數(shù)據(jù)保存在mysql數(shù)據(jù)庫(kù)的user表中,所以也可以直接對(duì)其進(jìn)行操作(不建議)
select User,Host,password_expired from user;
3.自增主鍵
自增,如果為某列設(shè)置自增列,插入數(shù)據(jù)時(shí)無(wú)需設(shè)置此列,默認(rèn)將自增(表中只能有一個(gè)自增列)
1、對(duì)于自增列,必須是索引(含主鍵)。
2、對(duì)于自增可以設(shè)置步長(zhǎng)和起始值
? ? ? ? ? ? ? ? ? ? show session variables like 'auto_inc%';
? ? ? ? ? ? ? ? ? ? set session auto_increment_increment=2;
? ? ? ? ? ? ? ? ? ? set session auto_increment_offset=10;
? ? ? ? ? ? ? ? ? ? shwo global? variables like 'auto_inc%';
? ? ? ? ? ? ? ? ? ? set global auto_increment_increment=2;
? ? ? ? ? ? ? ? ? ? set global auto_increment_offset=10;