日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql running_mysql常用命令

發布時間:2023/12/19 数据库 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql running_mysql常用命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 導出數據:

mysqldump --opt test > mysql.test

即將數據庫test數據庫導出到mysql.test文件,后者是一個文本文件

如:mysqldump -u root -p123456 --databases dbname > mysql.dbname

就是把數據庫dbname導出到文件mysql.dbname中。

2. 導入數據:

mysql -u root -p123456 < mysql.dbname。

mysqlimport -u root -p123456 < mysql.dbname。

3. 將文本數據導入數據庫:

文本數據的字段數據之間用tab鍵隔開。

use test;

load data local infile "文件名" into table 表名;

1:使用SHOW語句找出在服務器上當前存在什么數據庫:

mysql> SHOW DATABASES;

2:2、創建一個數據庫MYSQLDATA

mysql> CREATE DATABASE MYSQLDATA;

3:選擇你所創建的數據庫

mysql> USE MYSQLDATA; (按回車鍵出現Database changed 時說明操作成功!)

4:查看現在的數據庫中存在什么表

mysql> SHOW TABLES;

5:創建一個數據庫表

mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));

6:顯示表的結構:

mysql> DESCRIBE MYTABLE;

7:往表中加入記錄

mysql> insert into MYTABLE values ("hyq","M");

8:用文本方式將數據裝入數據庫表中(例如D:/mysql.txt)

mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;

9:導入.sql文件命令(例如D:/mysql.sql)

mysql>use database;

mysql>source d:/mysql.sql;

10:刪除表

mysql>drop TABLE MYTABLE;

11:清空表

mysql>delete from MYTABLE;

12:更新表中數據

mysql>update MYTABLE set sex="f" where name='hyq';

posted on 2006-01-10 16:21 happytian 閱讀(6) 評論(0) 編輯 收藏 收藏至365Key

13:備份數據庫

mysqldump -u root 庫名>xxx.data

14:例2:連接到遠程主機上的MYSQL

假設遠程主機的IP為:110.110.110.110,用戶名為root,密碼為abcd123。則鍵入以下命令:

mysql -h110.110.110.110 -uroot -pabcd123

(注:u與root可以不用加空格,其它也一樣)

15.修改密碼

mysqladmin -u root -p password 123456

回車出現

Enter password: ( 注:這是叫你輸入原密碼. 剛安裝時密碼為空,所以直接回車即可)

此時mysql 中賬號 root 的密碼 被改為 123456 安裝完畢

--列出指定的列select name, owner form pet

--直接進行算術運算,對字段起別名select sin(1+2) as sin

--where條件select * from pet where (birth>'1980' and species='dog') or species='bird'

--對null的條件select * from pet where sex is not null

--所有名字第四位是n的寵物信息是select * from pet where owner like '___n%'

--所有主人名叫gwen或benny的寵物select * from pet where owner in ('gwen' , 'benny')

--查詢出生日期在90年代是寵物,相當與>= and ? <=

select * from pet where birth between '1990' and '1999'

--按主人姓名排序,相同的按寵物姓名倒序排列select * from pet order by owner, name desc

--查詢性別為公的寵物,按生日倒序排列select * from pet where sex='m' order by birth desc

--char_lenngth()返回的字符的長度,length()返回字節長度SELECT owner,length(owner),char_length(owner) FROM pet p;

--列出養有寵物狗的人名select distinct owner from pet where species='dog'

--用兩種方法查詢出所有狗和貓的名字、出生年份、出生月份select name, left(birth,4) as year, mid(birth, 6, 2) as month from pet

where species='dog' or species='cat'

select name, year(birth) as year, month(birth) as month from pet

where species in('dog','cat')

--查詢所有名字中存在字母'e'的人,將他們養的寵物按類別、年齡排序select name, species, birth

from pet

where owner like '%e%'

order by species,birth desc

--數字函數select round(2.345,2), truncate(2.345,2), mod(323,5)

--日期函數select now(), curdate(), curtime()

select adddate('2007-02-02', interval 31 day)

--求出所有寵物的年齡select name,birth,

truncate(datediff(now(),birth)/365,0) as age1,

year(now())-year(birth) - (dayofyear(birth)>dayofyear(now())) as age2

from pet

--分組函數select min(birth),max(birth),avg(birth),count(*),count(sex),

sum(birth)

from pet

--每種寵物各有幾只select species,count(*)

from pet

group by species

--查詢年齡最大的寵物的信息select * from pet where birth =

(select max(birth) from pet)

--每年各出生了幾只寵物select year(birth), count(*) from pet group by year(birth)\

--鳥和貓的性別比例select species, sex, count(*)

from pet

where species in ('cat','bird')

group by species, sex

--各種寵物年齡的和select species, sum(truncate(datediff(now(),birth)/365,0)) as SumAge

from pet

group by species

--數量大于1的寵物種類select species, count(*) as c

from pet

group by species

having c>=2

--基本雙表關聯select a.name,a.species, a.sex,b.date, b.type, b.remark

from pet a,event b

where a.name = b.name

--查詢寵物產仔時的年齡select a.name, a.species,

truncate(datediff(b.date,a.birth)/365,0) as age

from pet a,event b

where a.name = b.name and b.type='litter'

--90年代出生的狗的事件列表select a.name,birth,species,sex,date,type,remark

from pet a,event b

where a.name=b.name and birth between '1990' and '1999'

and species='dog'

--活著的寵物按發生的事件類型分組,看各種事件發生的次數select type, count(*)

from pet a, event b

where a.name=b.name and a.death is null

group by type

--記錄的事件數量超過1條的寵物信息select a.name,species,sex,count(*)

from pet a, event b

where a.name = b.name

group by b.name

having count(*)>=2

--列出發生了兩件事情的寵物的事件記錄信息select a.name,type,date,remark,b.species,b.sex,b.owner

from event a, pet b

where a.name=b.name and

b.name in

(

select name

from event

group by name

having count(*)=2

)

--插入語句insert into pet (name,species,birth)

values ('KKK','snake','2007-01-01');

insert into pet

values ('KK','Diane','cat','f',null,null);

insert into pet set name='k',owner='Benny'

--更新語句update pet set species='snake',sex='f',birth=now()

where name='k'

--將事件表中生日的日期,更新到pet表中相應寵物的birth字段update pet a

set birth = (

select date

from event b

where a.name=b.name and b.type='birthday'

)

where a.name in (

select name

from event

where type='birthday'

)

--刪除語句delete from pet where name like 'k%'

總結

以上是生活随笔為你收集整理的mysql running_mysql常用命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。