標籤:
1:
啟動或關閉mysql服務:service mysqld start,service mysqld stop(或/etc/init.d/mysqld start,/etc/init.d/mysqld stop)
2:
修改mysql密碼:mysql_secure_installation或mysqladmin -u使用者名稱 -p舊密碼 password 新密碼
3:
顯示MySQL版本資訊:select version();
4:
顯示MySQL日期資訊:select current_date();
5:
顯示MySQL庫:show databases;
6:
建立資料庫:create database fuckTable character set utf8 collate=utf8_general_ci;
7:
刪除資料庫:drop database fuckTable;
8:
切換資料庫:use fuckTable;
9:
串連mysql:mysql -u使用者名稱 -p
10:
退出mysql介面:quit或ctrl+c;
11:
顯示資料表:show tables;
12:
建立資料表:create table fuckTable(
fuckId int(10) unsigned not null auto_increment,
fuckName varchar(255) null,
fuckText char(100) default ‘-‘,
primary key(`fuckId`)
)engine=innodb default charset=utf8 collate=utf8_general_ci;
13:
為表添加欄位:alter table fuckTable add column `fuckColumn` decimal(10,2) default 0 after fuckText;
14:
修改欄位:alter table fuckTable `fuckColumn` `fuckColumn` decimal(8,2) default 0 comment ‘yourSister‘;
15:
建立FK:create table yourSisterTable(
ystId int(10) not null auto_increment,
upupFuckId int(10) not null,
primary key(`ystId`),
constraint upupFuckId_FK foreign key(upupFuckId) references fuckTable(fuckId)
)engine=innodb default charset=utf8 collate=utf8_general_ci;
16:
刪除資料表:drop table fuckTable;
17:
顯示建立資料庫的資訊:show create database fuckDB;
18:
顯示建立資料表的資訊:show create table fuckTable;
19:
顯示資料表資訊:desc fuckTable 或 show columns from fuckTable;
20:
資料表添加主鍵:alter table fuckTable add primary key(`fuckId`,`fuckxx`);
21:
資料表添加唯一索引:alter table fuckTable add unique `fuckUnique` (`fuckName`,`fuckxx`);
22:
資料表添加普通索引:alter table fuckTable add index `fuckIndex` (`fuckText`,`fuckxx`);
23:
刪除主鍵:alter table fuckTable drop primary key(`fuckId`);
24:
刪除唯一索引:alter table fuckTable drop unique `fuckUnique` (`fuckName`);
25:
刪除普通索引:alter table fuckTable drop index `fuckIndex` (`fuckText`);
26:
刪除欄位:alter table fuckTable drop fuckText;
27:
修改資料表名:alter table fuckTable rename to yourSisterTable;
28:
匯出資料庫(此時在mysql command line外面操作):
mysqldump -u使用者名稱 -p密碼 --no-data fuckDB > fuckDB.sql(此時匯出的是資料庫的結構,無資料)
mysqldump -u使用者名稱 -p密碼 fuckDB > fuckDB.sql(此時匯出的是資料庫的結構,包含表的資料)
29:
匯出資料表(此時在mysql command line外面操作):
mysqldump -u使用者名稱 -p密碼 --no-data fuckDB fuckTable > fuckTable.sql(此時匯出的是資料表的結構,無資料)
mysqldump -u使用者名稱 -p密碼 fuckDB fuckTable > fuckTable.sql(此時匯出的是資料表的結構,包含表的資料)
30:
匯入資料庫(此時在mysql command line外面操作):
mysql -uroot -p123456 fuckDB < fuckDB.sql
31:
匯入資料:source /root/upload/fuckDB.sql
32:
mysql分區:create table fuckTable(
id int(10) unsigned not null auto_increment,
addTime int(10) unsiged not null,
title varchar(255) not null,
content text,
primary key(`id`),
key `addTime` (`addTime`)
)engine=innodb default charset=utf8 collate=utf8_general_ci
partition by range(id) (
partition p0 values less than (3),
partition p1 values less than (6),
partition p2 values less than maxvalue
)
33:
查看分區資訊:select * from information_schema.partitions where table_name=‘fuckTable‘
34:
顯示mysql可用的變數:show variables
35:
mysql授權:grant all on *.* to ‘fuckLoginName‘@‘%‘ identified by ‘fuckPassword‘
36:
複製表結構:create table t2 like t1;
37:
複製表資料 insert into t2 select field1,field2 from t1;
38:
修改欄位屬性:alter table fuckTable change `field` `field` int(10);
39:
建立視圖:create view viewTable(field1,field2,field3) as select a.field1,a.field2,b.field3 from a,b;
40:刪除視圖:drop view viewTable;
41:mysql預先處理語句:
prepare statementName from "select * from fuckTable where id > ?";
set @i=3;
execute statementName using @i;
42:刪除預先處理語句:drop prepare statementName;
43:auto_increment重拍:alter table fuckTable auto_increment=1;
44:儲存:
delimiter //
create proceduce pFuck()
begin
set @i=1;
while @i < 100 do
insert into fuckTable values (concate(‘test‘,@i));
set @[email protected]+1;
end while;
end //
45:觸發器:
delimiter //
create trigger tFuck before update on fuckTable for each row
begin
update fuck2Table set title=new.title where title=old.title;
end //
mysql 命令列基本操作命令