当前位置:网站首页>Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
2022-07-05 21:28:00 【Raymond。】
pycharm Connected to the virtual machine mysql Sort out the problems encountered
1. pycharm Connect mysql database
The connection tutorial can be referred to PyCharm Connecting virtual machines MySql database .
2. pycharm Problems with connecting
2.1 mysql Version and driver issues
The version installed in the virtual machine is 5.1.49, Need to be in mysql for 5.1 Select the corresponding drive on .
The problem is solved by referring to the official documents Cannot connect to a database
2.2 Connection error timeout
The next day after the connection is successful , When I tested again, I found , Report errors :
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago
Reference resources MySQL The next morning, I made an error when I connected for the first time , resolvent
The reason is because mysql There is a problem with the configuration . stay mysql There are two timing operations in , The parameter name is interactive_timeout and wait_timeout. The meaning is as follows :
1)interactive_timeout: The number of seconds the server waits for activity before shutting down the interactive connection . The interactive client is defined in mysql_real_connect() Use in CLIENT_INTERACTIVE Option client .
Parameter default :28800 second (8 Hours )
(2)wait_timeout: The number of seconds the server waits for activity before shutting down non interactive connections .
When the thread starts , According to the global wait_timeout Value or global interactive_timeout Value initializes the session wait_timeout value , Depends on the client type ( from mysql_real_connect() Connection options for CLIENT_INTERACTIVE Definition ).
Parameter default :28800 second (8 Hours )
When a client connects to MySQL After the database , If the client does not disconnect itself , And do nothing ,MySQL The database will keep this connection "wait_timeout" All this time ( The unit is s, The default is 28800s, That is to say 8 Hours ), Beyond that time ,MySQL Database in order to save resources , The connection will be disconnected on the database side ; Of course , In the process , If the client has any operation on this connection ,MySQL The database will restart calculating this time .
Therefore, in order to prevent timeout , You need to increase the two timeout timers . For the method of change, see MySQL The next morning, I made an error when I connected for the first time , resolvent
2.3 SSH Connect MYSQL
stay PyCharm Connecting virtual machines MySql database The article mentions
Because we are connected to virtual machines MySQL, So you need to fill in SSH( Safety surgery agreement ), adopt SSH Securely connect to the virtual machine for data interaction
I solve this problem 2.2 In question , Reconnect the mysql Database time , Forgot to fill in ssh news , As a result, it has been disconnected . About ssh Relevant knowledge needs to be supplemented .
3. pycharm Problems in connecting to the database in the code
3.1 About modules MySQLdb
Report errors
ModuleNotFoundError: No module named ‘MySQLdb
I installed python The version is 3.9
MySQLdb Only support Python2., Not yet 3.
It can be used PyMySQL Instead of . Installation method :pip install PyMySQL
In the use of import sqlalchemy When combined with :import pymysql
pymysql.install_as_MySQLdb(), namely :
import pymysql
pymysql.install_as_MySQLdb()
from sqlalchemy import create_engine
Reference resources :
python3.6 Report errors ModuleNotFoundError: No module named ‘MySQLdb‘ And solutions
3.2 Wrong connection time_out
Report errors
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '...' (timed out)")
First, check whether the user is granted remote access permission .
After determining the endowments , see MySQL 3306 Whether the port listens ,
netstat -nltp | grep 3306
Finally, check the firewall status , Confirm that it is closed .
3.3 About create_engine usage
usage :
engine = create_engine(‘dialect+driver://username:[email protected]:port/database’)
dialect – Database type
driver – Database driven selection
username – Database user name
password – User password
host Server address
port port
database database
for example mysql:
mysql-python
engine = create_engine(‘mysql+mysqldb://scott:[email protected]/foo’)
For more data types, refer to python sqlalchemy in create_engine usage
边栏推荐
- Deployment of Jenkins under win7
- vant 源码解析 event.ts 事件处理 全局函数 addEventListener详解
- 终端安全能力验证环境搭建和渗透测试记录
- Simple getting started example of Web Service
- 阿里云有奖体验:用PolarDB-X搭建一个高可用系统
- Teach yourself to train pytorch model to Caffe (I)
- Li Kou ----- the maximum profit of operating Ferris wheel
- Viewrootimpl and windowmanagerservice notes
- EasyExcel的讀寫操作
- 浅聊我和一些编程语言的缘分
猜你喜欢
Clickhouse copy paste multi line SQL statement error
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
LeetCode_哈希表_困难_149. 直线上最多的点数
Teach yourself to train pytorch model to Caffe (I)
Influence of oscilloscope probe on measurement bandwidth
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
Opérations de lecture et d'écriture pour easyexcel
leetcode:1755. Sum of subsequences closest to the target value
张丽俊:穿透不确定性要靠四个“不变”
随机推荐
JMeter installation under win7
Is Kai Niu 2980 useful? Is it safe to open an account
Binary search
張麗俊:穿透不確定性要靠四個“不變”
Clickhouse copy paste multi line SQL statement error
Dictionary tree simple introductory question (actually blue question?)
2022-07-03-CKA-粉丝反馈最新情况
[daily training -- Tencent select 50] 89 Gray code (only after seeing the solution of the problem)
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
【案例】元素的显示与隐藏的运用--元素遮罩
Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»
面试官:并发编程实战会吗?(线程控制操作详解)
字典树简单入门题(居然是蓝题?)
Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
When a user logs in, there is often a real-time drop-down box. For example, entering an email will @qq com,@163. com,@sohu. com
Xlrd common operations
Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture
[case] Application of element display and hiding -- element mask
Selenium's method of getting attribute values in DOM
Wood board ISO 5660-1 heat release rate mapping test