一、Navicat
在生产环境中操作MySQL数据库还是推荐使用命令行工具mysql,但在我们自己开发测试时,
可以使用可视化工具Navicat,以图形界面的形式操作MySQL数据库

官网下载:https://www.navicat.com/en/products/navicat-for-mysql
网盘下载:https://pan.baidu.com/s/1bpo5mqj
链接:https://pan.baidu.com/s/1Hu-x0mPuSW3g9CxNFlnAng 密码:pqe5

# 打开 双击:
# D:\navicatformysql\Navicat for MySQL\navicat

需要掌握的基本操作
掌握:
#1. 测试+链接数据库
#2. 新建库
#3. 新建表,新增字段+类型+约束
#4. 设计表:外键
#5. 新建查询
#6. 备份库/表

注意:
批量加注释:ctrl+?键
批量去注释:ctrl+shift+?键

二、pymysql
介绍:
在python程序中操作数据库呢?这就用到了pymysql模块,
该模块本质就是一个套接字客户端软件,使用前需要事先安装
pip3 install pymysql
前提:
授权加创建
grant all on *.* to 'root'@'%' identified by '123';
flush privileges;

端口:3306
ip: 192.168.1.102
mysql -uroot -p123 -h 192.168.1.102

1.pymysql基本使用

           数据库 - Navicat与pymysql模块

 1 # -*- coding:utf-8 -*-
 2 """
 3 端口:3306
 4 ip: 192.168.1.102
 5 mysql -uroot -p123 -h 192.168.1.102
 6 
 7 """
 8 import pymysql
 9 
10 name = input('user>>>:').strip()           # egon1
11 password = input('password>>>:').strip()  # 123
12 
13 # 建连接
14 conn = pymysql.connect(
15     host = '192.168.1.102',
16     port = 3306,
17     user = 'root',
18     password = '123',
19     db = 'egon',
20     charset = 'utf8'
21 )
22 
23 # 拿游标
24 cursor = conn.cursor()
25 
26 # 执行sql语句
27 sql = 'select * from userinfo where name= "%s" and password = "%s"'%(name,password)
28 rows = cursor.execute(sql)
29 print(rows)
30 
31 # 关闭
32 cursor.close()
33 conn.close()
34 
35 # 进行判断
36 if rows:
37     print('登录成功')
38 else:
39     print('登录失败')
基本使用

相关文章:

  • 2020-05-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-02-07
  • 2021-12-15
  • 2021-09-28
  • 2021-12-11
猜你喜欢
  • 2021-11-15
  • 2022-12-23
  • 2021-11-27
  • 2021-07-02
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案