第十七周作業(yè)

1、 導(dǎo)入hellodb.sql生成數(shù)據(jù)庫

[root@centos8 workspace]# mysql -uroot -pddq123 < /root/workspace/hellodb_innodb.sql
[root@centos8 workspace]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.33 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use hellodb;
mysql> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes           |
| coc               |
| courses           |
| scores            |
| students          |
| teachers          |
| toc               |
+-------------------+
7 rows in set (0.00 sec)

(1) 在students表中油额,查詢年齡大于25歲泞坦,且為男性的同學(xué)的名字和年齡

mysql> describe  students;
+-----------+---------------------+------+-----+---------+----------------+
| Field     | Type                | Null | Key | Default | Extra          |
+-----------+---------------------+------+-----+---------+----------------+
| StuID     | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |
| Name      | varchar(50)         | NO   |     | NULL    |                |
| Age       | tinyint(3) unsigned | NO   |     | NULL    |                |
| Gender    | enum('F','M')       | NO   |     | NULL    |                |
| ClassID   | tinyint(3) unsigned | YES  |     | NULL    |                |
| TeacherID | int(10) unsigned    | YES  |     | NULL    |                |
+-----------+---------------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)

mysql> select Name,Age from students where Age>25 and Gender="M";
+--------------+-----+
| Name         | Age |
+--------------+-----+
| Xie Yanke    |  53 |
| Ding Dian    |  32 |
| Yu Yutong    |  26 |
| Shi Qing     |  46 |
| Tian Boguang |  33 |
| Xu Xian      |  27 |
| Sun Dasheng  | 100 |
+--------------+-----+
7 rows in set (0.00 sec)

(2) 以ClassID為分組依據(jù),顯示每組的平均年齡

mysql> select ClassID,avg(Age) from students group by ClassID order by ClassID;
+---------+----------+
| ClassID | avg(Age) |
+---------+----------+
|    NULL |  63.5000 |
|       1 |  20.5000 |
|       2 |  36.0000 |
|       3 |  20.2500 |
|       4 |  24.7500 |
|       5 |  46.0000 |
|       6 |  20.7500 |
|       7 |  19.6667 |
+---------+----------+
8 rows in set (0.00 sec)

(3) 顯示第2題中平均年齡大于30的分組及平均年齡

mysql> select ClassID,avg(Age) from students  group by ClassID having avg(Age)>30 order by ClassID;
+---------+----------+
| ClassID | avg(Age) |
+---------+----------+
|    NULL |  63.5000 |
|       2 |  36.0000 |
|       5 |  46.0000 |
+---------+----------+
3 rows in set (0.00 sec)

(4) 顯示以L開頭的名字的同學(xué)的信息

mysql> select * from students where Name like "L%" ;
+-------+-------------+-----+--------+---------+-----------+
| StuID | Name        | Age | Gender | ClassID | TeacherID |
+-------+-------------+-----+--------+---------+-----------+
|     8 | Lin Daiyu   |  17 | F      |       7 |      NULL |
|    14 | Lu Wushuang |  17 | F      |       3 |      NULL |
|    17 | Lin Chong   |  25 | M      |       4 |      NULL |
+-------+-------------+-----+--------+---------+-----------+
3 rows in set (0.00 sec)

2愕贡、數(shù)據(jù)庫授權(quán)magedu用戶草雕,允許192.1.0/24網(wǎng)段可以連接mysql

mysql> create user 'magedu'@'192.168.1.0/24' identified by 'magedu123';
Query OK, 0 rows affected (0.00 sec)


#在192.168.1.0/24網(wǎng)段上登錄mysql服務(wù)器
[root@centos8 ~]# ip address show ens3 |grep inet
    inet 192.168.1.8/24 brd 192.168.1.255 scope global noprefixroute ens3
    inet6 fe80::42b0:4ef8:a735:7ae/64 scope link noprefixroute

[root@centos8 ~]# mysql -umagedu -p -h192.168.0.8
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.33 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市固以,隨后出現(xiàn)的幾起案子墩虹,更是在濱河造成了極大的恐慌,老刑警劉巖憨琳,帶你破解...
    沈念sama閱讀 211,194評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件诫钓,死亡現(xiàn)場離奇詭異,居然都是意外死亡篙螟,警方通過查閱死者的電腦和手機菌湃,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,058評論 2 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來闲擦,“玉大人慢味,你說我怎么就攤上這事∈洌” “怎么了纯路?”我有些...
    開封第一講書人閱讀 156,780評論 0 346
  • 文/不壞的土叔 我叫張陵,是天一觀的道長寞忿。 經(jīng)常有香客問我驰唬,道長,這世上最難降的妖魔是什么腔彰? 我笑而不...
    開封第一講書人閱讀 56,388評論 1 283
  • 正文 為了忘掉前任叫编,我火速辦了婚禮,結(jié)果婚禮上霹抛,老公的妹妹穿的比我還像新娘搓逾。我一直安慰自己,他們只是感情好杯拐,可當我...
    茶點故事閱讀 65,430評論 5 384
  • 文/花漫 我一把揭開白布霞篡。 她就那樣靜靜地躺著世蔗,像睡著了一般。 火紅的嫁衣襯著肌膚如雪朗兵。 梳的紋絲不亂的頭發(fā)上污淋,一...
    開封第一講書人閱讀 49,764評論 1 290
  • 那天,我揣著相機與錄音余掖,去河邊找鬼寸爆。 笑死,一個胖子當著我的面吹牛盐欺,可吹牛的內(nèi)容都是我干的赁豆。 我是一名探鬼主播,決...
    沈念sama閱讀 38,907評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼冗美,長吁一口氣:“原來是場噩夢啊……” “哼歌憨!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起墩衙,我...
    開封第一講書人閱讀 37,679評論 0 266
  • 序言:老撾萬榮一對情侶失蹤务嫡,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后漆改,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體心铃,經(jīng)...
    沈念sama閱讀 44,122評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,459評論 2 325
  • 正文 我和宋清朗相戀三年挫剑,在試婚紗的時候發(fā)現(xiàn)自己被綠了否淤。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片测僵。...
    茶點故事閱讀 38,605評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡夺刑,死狀恐怖魂莫,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情哲戚,我是刑警寧澤奔滑,帶...
    沈念sama閱讀 34,270評論 4 329
  • 正文 年R本政府宣布,位于F島的核電站顺少,受9級特大地震影響朋其,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜脆炎,卻給世界環(huán)境...
    茶點故事閱讀 39,867評論 3 312
  • 文/蒙蒙 一梅猿、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧秒裕,春花似錦袱蚓、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,734評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽爽撒。三九已至,卻和暖如春响蓉,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背哨毁。 一陣腳步聲響...
    開封第一講書人閱讀 31,961評論 1 265
  • 我被黑心中介騙來泰國打工枫甲, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人扼褪。 一個月前我還...
    沈念sama閱讀 46,297評論 2 360
  • 正文 我出身青樓想幻,卻偏偏與公主長得像,于是被迫代替她去往敵國和親话浇。 傳聞我的和親對象是個殘疾皇子脏毯,可洞房花燭夜當晚...
    茶點故事閱讀 43,472評論 2 348

推薦閱讀更多精彩內(nèi)容

  • 1、 導(dǎo)入hellodb.sql生成數(shù)據(jù)庫 (1) 在students表中幔崖,查詢年齡大于25歲食店,且為男性的同學(xué)的名...
    陌路殘蟬閱讀 177評論 1 0
  • 1、 導(dǎo)入hellodb.sql生成數(shù)據(jù)庫 (1) 在students表中赏寇,查詢年齡大于25歲吉嫩,且為男性的同學(xué)的名...
    紫火紅云閱讀 227評論 1 0
  • 一、 導(dǎo)入hellodb.sql生成數(shù)據(jù)庫 1嗅定、在students表中自娩,查詢年齡大于25歲,且為男性的同學(xué)的名字和...
    亨利閱讀 111評論 1 0
  • 1渠退、導(dǎo)入hellodb.sql生成數(shù)據(jù)庫 [root@centos7 ~]# mysql -p < hellodb...
    Gustav_man閱讀 105評論 0 0
  • 1忙迁、 導(dǎo)入hellodb.sql生成數(shù)據(jù)庫 (1) 在students表中,查詢年齡大于25歲碎乃,且為男性的同學(xué)的名...
    沐熙一葉_Leaf閱讀 201評論 1 0