(1)查詢存在的資料庫
show databases;
選擇所要的某個資料庫 use databasename;
(2)查詢當前資料庫存在的所有的表
show tables;
(3)查詢表結構
describe tablename;
(4)查詢**列的屬性
show columns from tablename;
(5)查詢記錄
select name from tablename where id=***;
(6)查詢當前時間
select now();
select current_time;
(7)查詢當前日期
select current_date;
(8)查詢當前使用者
select user();
(9)查詢資料庫版本
select version();
(10)查詢當前使用的資料庫
select database();
(11)查詢當前伺服器支援哪個儲存引擎
show engines;
(1)建立資料庫
create database databasename;
create database database_name default character set utf8;
(2)建立一張表
create table tablename (name varchar(20), *** char(1));
create table if not exists students(……); //建立表是先判斷表是否存在
(3)建立臨時表:(建立臨時表linshi)
create temporary table linshi(name varchar(10));
(4)從已經有的表table1中複製表的結構到表table2
create table table2 select * from table1 where 1<>1; //只複製表結構
create table table2 select * from table1; //複製表結構和表中的資料
(5)往表中links加入記錄
insert into links(name,url) values('xiaoxiaozi','');
insert into links set name='xiaoxiaozi',url='';
(1)對錶重新命名
alter table tablename1 rename as tablename2;
(2)修改列的型別
alter table tablename modify id int unsigned; //修改列id的型別為int unsigned
alter table tablename change id sid int unsigned; //修改列id的名字為sid,而且把屬性修改為int unsigned
(3)更新表中資料
update tablename set ***='f' where name='john';
(1)刪除某個資料庫
drop database databasename; //刪除資料庫前,沒有提示
mysqladmin drop databasename; //刪除資料庫前,有提示
(2)刪除某張表
drop table tablename;
(3)清空某張表
delete from tablename;
(4)刪除符合條件的某些記錄
delete from tablename where id=***;
(5)刪除授權:
revoke all privileges on *.* from root@」%」;
delete from user where user=」root」 and host=」%」;
flush privileges; //重新整理資料庫
(1)備份資料庫:(將資料庫test備份)
mysqldump -u root -p test>c:\test.txt
(2)備份**:(備份test資料庫下的mytable**)
mysqldump -u root -p test mytable>c:\test.txt
(3)將備份資料匯入到資料庫:(導回test資料庫)
mysql -u root -p test
mysql基本常用命令 MySQL常用命令(一)
cmd提示框中的mysql基礎命令 一 命令 連線mysql伺服器 mysql h localhost u root p 展示所有資料庫 show databases 選擇資料庫 use database 展示所選資料下所有表 show tables 設定資料庫編碼 set names gbk 用s...
mysql巡檢常用命令 mysql 常用命令
客戶端連線 進入命令列,windows cmd,連線 mysql u 使用者名稱 p密碼 h 伺服器ip位址 p 伺服器端mysql埠號 d 資料庫名 注意 1 伺服器端口標誌 p一定要大些以區別於使用者 p,如果直接連線資料庫標誌 d也要大寫 2 如果要直接輸入密碼 p後面不能留有空格如 pmyp...
mysql常用命令總結 mySql常用命令總結
總結一下自己常用的mysql資料庫的常用命令 mysql u root p 進入mysql bin目錄後執行,回車後輸入密碼連線。資料庫操作 1 create database dbname 建立資料庫,資料庫名為dbname 2 create database todo default chara...