MySQL命令行下18個常用命令
在日常的網(wǎng)站維護和管理中,會用到非常多的SQL語句,
熟練使用對網(wǎng)站管理有很多好處,尤其是站群管理的時候。
下面列一些常用的命令做備記。
1、顯示數(shù)據(jù)庫
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ù)庫testdb:
create database testdb;
5、預(yù)防性創(chuàng)建數(shù)據(jù)庫:
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)建一個表table1:
create table tmp as select * from table1;
15、刪除表table1:
drop table if exists table1; drop table if exists tmp;
16、備份數(shù)據(jù)庫testdb
mysqldump -h 192.168.3.143 -u root -p pwd -x --default-character-set=gbk >C:\testdb.sql
17、刪除數(shù)據(jù)庫testdb
drop database testdb;
18、恢復(fù)testdb數(shù)據(jù)庫
首先先建立testdb數(shù)據(jù)庫,然后用下面命令進行本地恢復(fù)
mysql -u root -pleizhimin testdb <C:\testdb.sql
這18個MYSQL命令都是管理員在日常維護中經(jīng)常會用到的,熟練使用這些命令會使你的工作非常輕松
相關(guān)文章
Mysql 命令行模式訪問操作mysql數(shù)據(jù)庫操作
這篇文章主要介紹了Mysql 命令行模式訪問操作mysql數(shù)據(jù)庫操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08SQL update多表關(guān)聯(lián)更新方法解讀
這篇文章主要介紹了SQL update 多表關(guān)聯(lián)更新方法,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08windows 10 下mysql-8.0.17-winx64的安裝方法圖解
這篇文章主要介紹了windows 10 mysql-8.0.17-winx64的方法,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08mysql數(shù)據(jù)庫常見的優(yōu)化操作總結(jié)(經(jīng)驗分享)
這篇文章主要給大家介紹了關(guān)于mysql數(shù)據(jù)庫常見的優(yōu)化操作,文章總結(jié)的都是個人日常開發(fā)使用mysql數(shù)據(jù)庫的經(jīng)驗所得,其中包括Index索引、少用SELECT*、EXPLAIN SELECT以及開啟查詢緩存等相關(guān)資料,相信會對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-04-04