在日常的網站維護和MYSQL資料庫管理中,我們常常會用到非常多的MYSQL指令,為了方便大家整理,小編列舉了18個管理MYSQL資料庫時最常使用的指令。
在日常的網站維護與管理中,會用到非常多的SQL語句,
熟練使用對網站管理有很多好處,尤其是站群管理的時候。
下面列一些常用的指令做備記。
1、顯示資料庫
show databases
顯示表格
show tables;
2、建立使用者
建立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、建立資料庫testdb:
create database testdb;
5、預防性建立資料庫:
create database if not testdb;
# 6、建立表格:
use testdb; create table table1( username varchar(12), password varchar(20));
7、預防性建立表aaa:
create table if not exists aaa(ss varchar(20));
8、檢視表格結構:
describe table1;
# 9、插入資料到表格table1:
insert into table1(username,password) values ('leizhimin','lavasoft'), ('hellokitty','hahhahah'); commit;
10、查詢表格table1:
select * from table1;
# 11、更改資料:
update table1 set password='hehe' where username='hellokitty'; commit;# 12、刪除資料:
delete from table1 where username='hellokitty'; commit;
alter table table1 add column( sex varchar(2) comment '性别', age date not null comment '年龄' ); commit;14、修改表格結構#########從查詢建立一個表格table1: ############
create table tmp as select * from table1;############ 15.刪除表格table1:###############
drop table if exists table1; drop table if exists tmp;#############16、備份資料庫testdb ########### ####
mysqldump -h 192.168.3.143 -u root -p pwd -x --default-character-set=gbk >C:\testdb.sql############17、刪除資料庫testdb ###############
drop database testdb;##################################################################################################################################################################################################################################### 18.恢復testdb資料庫######先建立testdb資料庫,然後用下面指令進行本地還原############
mysql -u root -pleizhimin testdb <C:\testdb.sql#########這18個MYSQL指令都是管理員在日常維護中常會用到的,熟練使用這些指令會讓你的工作非常輕鬆######相關推薦:#########教你使用MySQL:MySQL常用指令一覽_PHP教學############MYSQL常用指令與實用技巧############MySQL常用指令列總結收集############### ##########
以上是18個常用的MySQL指令的詳細內容。更多資訊請關注PHP中文網其他相關文章!