数字校园注册登录系统(简洁版)

# 终端安装pymysql库  pip install pymysql
/**** 杨祥民 ****/

/**** QQ:2042870085 ****/


import pymysql

def login(un, pw):
    """用户登录"""
    try:
        if cr.execute(f"select * from reg_login_127 where username='{un}'and password='{pw}';") == 1:
            print(f'用户{un}登录系统成功', '-' * 10)
        else:
            print(f'用户{un}登录系统失败', '-' * 10)
            if cr.execute(f"select * from reg_login_127 where username='{un}';") == 1:
                print("密码错误")
            else:
                print('账号不存在')
    except Exception as e:
        print(e)


def logon(un, pw):
    """用户注册"""
    try:
        """插入数据到数据表reg_login_127中"""
        cr.execute(f'insert into reg_login_127 (username,password) '
                        f"values ('{un}','{pw}');")
        connet.commit()
        print(f'用户{un}注册成功', '-' * 10)
    except Exception as e:
        print(e)


if __name__ == '__main__':
    try:
        connet = pymysql.connect(host='192.168.2.100',
                                      user='admin',
                                      passwd='adminpw',
                                      database='Digital_school')
        cr = connet.cursor()
    except pymysql.err.OperationalError as e:
        print('登录超时')
        print(e)

    """检测数据表是否存在"""
    try:
        if cr.execute(f"select * from information_schema.TABLES WHERE TABLE_NAME = 'reg_login_127'") == 1:
            print(f"数据表reg_login_127存在")
        else:
            cr.execute(f"create table reg_login_127(username char(20) unique key,password char(20))")
            connet.commit()
            print(f"数据表reg_login_127创建成功")
    except Exception as e:
        print(e)
    options = input('1--登录\n2--注册\n')
    if options == '1':
        username = input('用户名')
        password = input('密码')
        login(username,password)
    if options == '2':
        username = input('用户名')
        password = input('密码')
        logon(username,password)


/****数据库配置****/

show databases;    # 检查数据库是否存在

create database Digital_school;    # 创建数据库
grant all on Digital_school.* to 'test1'@'%' identified by 'test123' ; 
flush privileges;刷新MySQL的系统权限


/****数据库连接超时****/
#####  (2003, "Can't connect to MySQL server on '192.168.2.101' (timed out)")     ####
1、----检查防火墙是否放行或者直接关闭防火墙
systemctl status firewalld.service    # 查看防火墙状态

firewall-cmd --list-all  # 查看防火墙状态
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33 ens36
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

systemctl stop firewalld.service   # 关闭防火墙
2、----检查connect中的参数
connect常用参数:
hostname 连接的目标主机
port=SSH_PORT 指定端口
username=None 验证的用户名
password=None 验证的用户密码
database=None 指定数据库

 

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超爱小yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值