MySQL命令行下18個(gè)常用命令
在日常的網(wǎng)站維護(hù)和管理中,會(huì)用到非常多的SQL語句,
熟練使用對(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ì)使你的工作非常輕松
相關(guān)文章
Mysql 命令行模式訪問操作mysql數(shù)據(jù)庫(kù)操作
這篇文章主要介紹了Mysql 命令行模式訪問操作mysql數(shù)據(jù)庫(kù)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08
SQL update多表關(guān)聯(lián)更新方法解讀
這篇文章主要介紹了SQL update 多表關(guān)聯(lián)更新方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
windows 10 下mysql-8.0.17-winx64的安裝方法圖解
這篇文章主要介紹了windows 10 mysql-8.0.17-winx64的方法,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08
mysql數(shù)據(jù)庫(kù)常見的優(yōu)化操作總結(jié)(經(jīng)驗(yàn)分享)
這篇文章主要給大家介紹了關(guān)于mysql數(shù)據(jù)庫(kù)常見的優(yōu)化操作,文章總結(jié)的都是個(gè)人日常開發(fā)使用mysql數(shù)據(jù)庫(kù)的經(jīng)驗(yàn)所得,其中包括Index索引、少用SELECT*、EXPLAIN SELECT以及開啟查詢緩存等相關(guān)資料,相信會(huì)對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-04-04
mysql5.7單實(shí)例自啟動(dòng)服務(wù)配置過程
這篇文章主要介紹了mysql5.7單實(shí)例自啟動(dòng)服務(wù)配置的過程,附含配置源碼,有需要的朋友可以借鑒參考下,希望可以有所幫助,感謝閱讀2021-09-09

