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 5.7.13 安裝配置方法圖文教程(win10 64位)
這篇文章主要為大家分享了win10 64位下mysql 5.7.13 安裝配置方法圖文教程,感興趣的朋友可以參考一下2017-02-02
解決Mysql收縮事務(wù)日志和日志文件過大無法收縮問題
這篇文章主要介紹了解決Mysql收縮事務(wù)日志和日志文件過大無法收縮問題,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-08-08
利用frm和ibd文件恢復(fù)mysql表數(shù)據(jù)的詳細過程
總是遇到mysql服務(wù)意外斷開之后導(dǎo)致mysql服務(wù)無法正常運行的情況,使用Navicat工具查看能夠看到里面的庫和表,但是無法獲取數(shù)據(jù)記錄,提示數(shù)據(jù)表不存在,所以本文給大家介紹了利用frm和ibd文件恢復(fù)mysql表數(shù)據(jù)的詳細過程,需要的朋友可以參考下2024-04-04
mysql installer community 8.0.16.0安裝配置圖文教程
這篇文章主要為大家詳細介紹了mysql installer community 8.0.16.0安裝配置圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05
MySQL查看和優(yōu)化數(shù)據(jù)庫實例詳細信息的命令
本文詳細介紹了如何查看?MySQL?數(shù)據(jù)庫實例的信息,包括基本信息、配置參數(shù)、運行進程和性能監(jiān)控等方面,通過多個代碼示例,讀者可以掌握查看和管理數(shù)據(jù)庫實例的具體操作,這些方法和工具對于數(shù)據(jù)庫管理和維護非常重要,可以幫助我們確保數(shù)據(jù)庫的健康運行2024-05-05

