在日常的網(wǎng)站維護(hù)和管理中,會(huì)用到非常多的SQL語(yǔ)句,
熟練使用對(duì)網(wǎng)站管理有很多好處,尤其是站群管理的時(shí)候。
下面列一些常用的命令做備記。
1、顯示數(shù)據(jù)庫(kù)
show databases
顯示表
show tables;
2、創(chuàng)建用戶
創(chuàng)建root用戶密碼為123
use mysql; grant all on *.* to root@'%' identified by '123' with grant option; commit;
3、修改密碼
grant all on *.* to xing@'localhost' identified by '123456' with grant option; update user set password = password('newpwd') where user = 'xing' and host='localhost'; flush privileges;4、創(chuàng)建數(shù)據(jù)庫(kù)testdb:
create database testdb;
5、預(yù)防性創(chuàng)建數(shù)據(jù)庫(kù):
create database if not testdb;
6、創(chuàng)建表:
use testdb; create table table1( username varchar(12), password varchar(20));
7、預(yù)防性創(chuàng)建表aaa:
create table if not exists aaa(ss varchar(20));
8、查看表結(jié)構(gòu):
describe table1;
9、插入數(shù)據(jù)到表table1:
insert into table1(username,password) values ('leizhimin','lavasoft'), ('hellokitty','hahhahah'); commit;10、查詢表table1:
select * from table1;
11、更改數(shù)據(jù):
update table1 set password='hehe' where username='hellokitty'; commit;
12、刪除數(shù)據(jù):
delete from table1 where username='hellokitty'; commit;
13、給表添加一列:
alter table table1 add column( sex varchar(2) comment '性別', age date not null comment '年齡' ); commit;
14、修改表結(jié)構(gòu)
從查詢創(chuàng)建一個(gè)表table1:
create table tmp as select * from table1;
15、刪除表table1:
drop table if exists table1; drop table if exists tmp;
16、備份數(shù)據(jù)庫(kù)testdb
mysqldump -h 192.168.3.143 -u root -p pwd -x --default-character-set=gbk >C:/testdb.sql
17、刪除數(shù)據(jù)庫(kù)testdb
drop database testdb;
18、恢復(fù)testdb數(shù)據(jù)庫(kù)
首先先建立testdb數(shù)據(jù)庫(kù),然后用下面命令進(jìn)行本地恢復(fù)
mysql -u root -pleizhimin testdb <C:/testdb.sql
這18個(gè)MYSQL命令都是管理員在日常維護(hù)中經(jīng)常會(huì)用到的,熟練使用這些命令會(huì)使你的工作非常輕松
新聞熱點(diǎn)
疑難解答
圖片精選