1.使用Python操作MySQL数据库 在windows系统中安装好Mysql8.0.23和python3.8.7,然后再完成下面题目中的各项操作。 现有以下三个表格: 表1 学生表:Student(主码为Sno) 学号(Sno) 姓
1.使用Python操作MySQL数据库
在windows系统中安装好Mysql8.0.23和python3.8.7,然后再完成下面题目中的各项操作。
现有以下三个表格:
表1 学生表:Student(主码为Sno)
学号(Sno) | 姓名(Sname) | 性别(Ssex) | 年龄(Sage) | 所在系别(Sdept) |
10001 | Jack | 男 | 21 | CS |
10002 | Rose | 女 | 20 | SE |
10003 | Michael | 男 | 21 | IS |
10004 | Hepburn | 女 | 19 | CS |
10005 | Lisa | 女 | 20 | SE |
表2 课程表:Course(主码为Cno)
课程号(Cno) | 课程名(Cname) | 学分(Credit) |
00001 | DataBase | 4 |
00002 | DataStructure | 4 |
00003 | AlGorithms | 3 |
00004 | OperatingSystems | 5 |
00005 | ComputerNetwork | 4 |
表3 选课表:SC(主码为Sno,Cno)
学号(Sno) | 课程号(Cno) | 成绩(Grade) |
10002 | 00003 | 86 |
10001 | 00002 | 90 |
10002 | 00004 | 70 |
10003 | 00001 | 85 |
10004 | 00002 | 77 |
10005 | 00003 | 88 |
10001 | 00005 | 91 |
10002 | 00002 | 79 |
10003 | 00002 | 83 |
10004 | 00003 | 67 |
通过编程实现以下题目:
import pymysql.cursorsconnect = pymysql.Connect( host='localhost', port=3306, user='root', passwd='abc123', db='school', charset='utf8' )cursor = connect.cursor()cursor.execute("""SELECT Student.Sno, Student.Sname, Student.Sdept, Course.Cno, Course.Cname, SC.GradeFROM StudentJOIN SC ON Student.Sno = SC.SnoJOIN Course ON SC.Cno = Course.CnoWHERE Student.Sno = '10002';""")result = cursor.fetchall()for x in result: print(x)connect.close()
import pymysql.cursorsconnect = pymysql.Connect( host='localhost', port=3306, user='root', passwd='abc123', db='school', charset='utf8' )cursor = connect.cursor()cursor.execute("""SELECT Student.Sno, Student.Sname, Student.Sdept, Course.Cno, Course.Cname, SC.GradeFROM StudentJOIN SC ON Student.Sno = SC.SnoJOIN Course ON SC.Cno = Course.CnoWHERE SC.Grade > 85;""")result = cursor.fetchall()for x in result: print(x)connect.close()
import pymysql.cursorsconnect = pymysql.Connect( host='localhost', port=3306, user='root', passwd='abc123', db='school', charset='utf8' )cursor = connect.cursor()cursor.execute("""UPDATE CourseSET Credit = 5WHERE Cno = '00001' AND Cname = 'DataBase';""")print("修改成功!")cursor.execute("""SELECT Cno,Cname, CreditFROM CourseWHERE Cno = '00001';""")result = cursor.fetchone()print(result)connect.close()
import pymysql.cursorsconnect = pymysql.Connect( host='localhost', port=3306, user='root', passwd='abc123', db='school', charset='utf8' )cursor = connect.cursor()cursor.execute("""INSERT INTO SC (Sno, Cno, Grade)VALUES ('10005', '00004', 73);""")connect.commit()print("添加成功!")cursor.execute("""SELECT Student.Sno, Student.Sname, Student.Sdept, Course.Cno, Course.Cname, SC.GradeFROM StudentJOIN SC ON Student.Sno = SC.SnoJOIN Course ON SC.Cno = Course.CnoWHERE Student.Sno = '10005';""")result = cursor.fetchall()for x in result: print(x)connect.close()
import pymysql.cursorsconnect = pymysql.Connect( host='localhost', port=3306, user='root', passwd='abc123', db='school', charset='utf8' )cursor = connect.cursor()cursor = connect.cursor()cursor.execute("""DELETE FROM Student WHERE Sno = '10003';""")connect.commit()cursor.execute("""DELETE FROM SC WHERE Sno = '10003';""")connect.commit()print("删除成功!")connect.close()
2.使用Shell命令操作HDFS
在Windows系统中安装hadoop3.1.3,然后完成下面题目中的各项操作:
1.使用自己的用户名登录Windows系统,启动Hadoop,为当前登录的Windows用户在hdfs中创建用户目录“/user/[用户名]”;
hadoop fs -mkdir /userhadoop fs -mkdir /user/xiaoguanhadoop fs -ls /user
2.接着在HDFS的目录“/user/[用户名]”下,创建test目录;
hadoop fs -mkdir /user/xiaoguan/testhadoop fs -ls /user/xiaoguan
3.将Windows系统本地的一个文件上传到HDFS的test目录中,并查看上传后的文件内容;
hadoop fs -put E:\test.txt /user/xiaoguan/testhadoop fs -ls /user/xiaoguan/testhadoop fs -cat /user/xiaoguan/test/test.txt
4.将HDFS目录test复制到Windows本地文件系统的某个目录下。
hadoop fs -get /user/xiaoguan/test/test.txt D:\testdir D:\test
来源地址:https://blog.csdn.net/m0_60946919/article/details/131324798
--结束END--
本文标题: 熟悉MySQL和HDFS操作
本文链接: https://lsjlt.com/news/421650.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0