1. use pycharm Failed to install third party package , Newspaper is similar to “sort" Error of , Just switch to the terminal

2. Mac The terminal failed to install the third package , Newspaper is similar to “

PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/crypto/__init__.py'“ Error of : shell Add before order sudo

3. Xiecheng news __sys__:1: RuntimeWarning: coroutine '***' was never awaited:

The reason for this in my code is that I should write “from tdqm import tdqm”, I wrote "import tdqm" , Then call directly tdqm() Method

4. 2003, "Can't connect to MySQL server on 'localhost' (10061)"

I looked up some information on the Internet , But it doesn't solve my problem . I came across an article that inspired me , take host from localhost Change to 127.0.0.1 ,( My premise is Already installed mysql as well as mysql The client of navicat). Problem solving . This kind of questions can also be referred to on the Internet :

https://blog.csdn.net/chenhua1125/article/details/79489298  【MySQL Remote connection failed ( Error code :2003)】

https://www.cnblogs.com/YunnuoFan/p/8482449.html   【mysql The characteristics of connection and the posture of dragging library 】

Detailed text , At the bottom of this page .

5  Pycharm function .py file , There's a lot of useless information on the console , It's a naming problem

C:\Python35\python3.exe "E:\Program Files\JetBrains\PyCharm 2017.1.1\helpers\pycharm\_jb_unittest_runner.py" --path F:/PythonCode/kaoshi/test.py
Testing started at 20:13 ...
 Launching unittests with arguments python -m unittest discover -s F:/PythonCode/kaoshi -p test.py -t F:\PythonCode\kaoshi in F:\PythonCode\kaoshi
123456

Ran 0 tests in 0.000s

OK

Process finished with exit code 0

Empty test suite.

terms of settlement ( Reference resources  https://blog.csdn.net/chenhua1125/article/details/79489298):

stay pycharm The file name in cannot be named test, Function names cannot be named test, This is because test stay python In the library are keywords , There was a conflict

After a console problem :

The right thing to do is not Unittests in test.py

python There are a lot of keywords in , Such output is generally keyword conflict , Try changing the function name or file name

【】

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

terms of settlement :

By default ,Mysql It will be installed later in /tmp Create one in the directory mysql.sock file , If the file is missing Mysql Will not start properly , resolvent : Use mysqld_safe Start and solve ;


1
2
3
4
5
#basedir:mysql The installation path , Default in /usr/local/mysql Next ;datadir: Database storage path , Default in /usr/local/mysql/data
# After starting with the following command , Will be in /tmp/ Next build one mysql.sock file
#./ That is to say :/usr/local/mysql/bin
 
$ ./mysqld_safe  --user=mysql --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data &

【MySQL Remote connection failed ( Error code :2003)】

One environmental information

  • Server system :Oracle Linux 7.3
  • The server MySQL edition :MySQL 5.7.20
  • The local system :win10
  • Local client :Navicat for MySQL 10.1.7
  • Local development environment :python(3.6.3),PyMySQL(0.8.0)
  • hypothesis : The login user name is admin, The password for adminpwd ,MySQL Connection port 3306

Two Problem description

  • Local client and code connection failed : 2003, "Can't connect to MySQL server on '192.168.1.166' (10061)"

  • python Connect MySQL Code
import pymysql
conn= pymysql.connect(
host='192.168.1.166',
port = 3306,
user='admin',
passwd='adminpwd',
db ='test',
charset='utf8'
)
# Use cursor Method get operation cursor
cur = conn.cursor()
# Use execute Method execution sql sentence
cur.execute("select version()")
# Use fetchone() Method to get a database
data = cur.fetchone()
print("datebase version : %s"%data)
# Close database connection
conn.close()
  • python Connect MySQL Report errors
Traceback (most recent call last):
File "D:/JetBrains/test/study_test/mysql_test1.py", line 15, in <module>
charset='utf8'
File "D:\JetBrains\pyEnv\python363\lib\site-packages\pymysql\__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "D:\JetBrains\pyEnv\python363\lib\site-packages\pymysql\connections.py", line 699, in __init__
self.connect()
File "D:\JetBrains\pyEnv\python363\lib\site-packages\pymysql\connections.py", line 967, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '192.168.1.166' (timed out)")

3、 ... and Official document description

 "The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server."
Jinshan translation : error (2003 year ) Can't connect to “server”(10061) Upper mysql The server , Indicates that the network connection has been rejected . You should check if there is a mysql The server is running , Whether it has network connection enabled , And the network port you specified is configured on the server .

Four To solve the process

  • (1) Xshell Remote login server , use “ps aux|grep mysql” Command view ,MySQL Service started :

  • (2) use "vim my.cnf" Command view my.cnf file ( stay MySQL Installation directory , My position is /usr/local/mysql/my.cnf), Modify its corresponding value and restart MySQL. The corresponding contents are as follows :
[mysqld]
bind-address = 0.0.0.0 # Indicates that any host is allowed to log in MySQL
port=3306 # Express MySQL For the run port 3306
  • (3) use “mysql -u admin -p” command , Enter the password “adminpsw” Can log in to the server normally MySQL
mysql> show global variables like 'port'; # see MySQL The actual port that runs 
+---------------+-------
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.01 sec)
 mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | admin |
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
5 rows in set (0.00 sec)
 # If the above query results ,admin User corresponding host Not for %, Then modify the user permissions 
# Note here that , You need to bring your password when you modify your permissions (IDENTIFIED BY 'adminpwd'), Although I don't know the specific principle , But without the password, the client still can't access remotely MySQL.
 mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'adminpwd' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
  • (4) thus , My local Navicat The client has been able to access the server normally , But running the above python Connect MySQL The code still reports the same error .

  • (5) Check the online information that the firewall may be blocked 3306 port , Local cmd"ping 192.168.1.166" can Ping through , Reuse ”telnet 192.168.1.166 3306“ Command to check if the port is masked , The result is " on connection 192.168.1.166... Unable to open connection to host . In the port 3306: The connection fails ", It's a firewall problem
    ( If Win10 telnet Not an internal or external command , Solution reference connection :https://jingyan.baidu.com/article/1e5468f9033a71484961b7d7.html)

  • (6) At first I thought it was about my local firewall , So I shut down the local firewall , As a result, the problem has not been solved .
  • (7) In fact, it should be the firewall problem of the remote server . Remote login server ( I use root User logged in ), Check firewall status
systemctl start firewalld # Turn on the firewall 
systemctl stop firewalld # Turn off firewall
systemctl status firewalld # Check firewall status
  • (8) After closing the remote server firewall , Run local run local python Connect MySQL Code ,MySQL Successful connection
[root@db sysconfig]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since 3、 ... and 2018-02-28 17:18:10 CST; 7s ago
Docs: man:firewalld(1)
Main PID: 5452 (firewalld)
CGroup: /system.slice/firewalld.service
└─5452 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
[root@db sysconfig]# systemctl stop firewalld
[root@db sysconfig]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
  • (9) If you think it's not safe to turn off the firewall , Can open the remote server's iptables( Install or upgrade commands “yum install iptables”)( I use root User logged in ), And use “vi /etc/sysconfig/iptables” Check 3306 Is the port open , If not , Add to the file “-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT”( As shown below ), Save the file and use “service iptables restart” Command restart iptables
# Generated by iptables-save v1.4.21 on Wed Feb 28 12:19:33 2018
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [34:3136]
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT ## Plus this trip
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibite
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Wed Feb 28 12:19:33 2018
~
~
"/etc/sysconfig/iptables" 17L, 654C
  • (10) Run local python Connect MySQL Code , give the result as follows :
datebase version : 5.7.20-enterprise-commercial-advanced
 
 
 
 

【mysql The characteristics of connection and the posture of dragging library 】

0x01. Preface

occasionally , Some people have questions like this ?

When netstat -ano Find out 3306 Monitor in 0.0.0.0 On , It can be judged whether mysql It's open to the outside world

The answer, of course, is No .

0x02. mysql Connection characteristics

Now we can do a test ,mysql Monitor in 0.0.0.0 On

And the server's mysql The user settings are as follows :

We need to know localhost、127.0.0.1、::1 These three host Priority exists , Their priorities go from high to low . It can be understood in this way :

If localhost and 127.0.0.1 The respective passwords are 123 and 456, So finally, log in locally mysql The password for is 123, instead of 456

  1.  
    [root@helen ~]# telnet 123.55.91.39 3306
  2.  
    Trying 123.55.91.39...
  3.  
    Connected to 123.55.91.39.
  4.  
    Escape character is '^]'.
  5.  
    GHost '115.29.170.215' is not allowed to connect to this MySQL serverConnection closed by foreign host.

use navicat The connection shows that the error code returned is 1130. It means you can't connect


Now we add a new non root user , And will host Change it to %, At this point, you can see that the error code returned is 1045.

namely : as long as host There is %, Connect mysql Error will be returned 1045 Error code .

also telnet The returned results are as follows , You can see mysql The version is 5.5.16-log

  1.  
    [root@helen ~]# telnet 123.55.91.39 3306
  2.  
    Trying 123.55.91.39...
  3.  
    Connected to 123.55.91.39.
  4.  
    Escape character is '^]'.
  5.  
    N
  6.  
    5.5.16-logdt=n4V5D^-d1f0XMYX-mysql_native_passwordConnection closed by foreign host.

0x03. utilize navicat Exported scripts

navicat When connecting to a database, you can use http passageway . Usage is as follows :
First, put the script file exported in the figure below on the server , Through the script file url To connect . It's a lot more convenient than other take off scripts .

however win Version of navicat There's no button ,mac The version has .win The version is in navicat Installation directory .

When connecting , stay http Fill in the channel address in the options http://123.55.91.39:8089/ntunnel_mysql.php

Host name :localhost, So you can use it normally navicat Same connection

Finally, the effect of taking off pants :

0x04. summary

    1. mysql return 1130 It means that there is no account to open the external connection
    2. mysql return 1045 It means that there is an account to open the external connection , But I don't know which account
    3. localhost、127.0.0.1、::1 These three priorities go from high to low
 
 
 
 

【Python】【 A collection of questions 】 More articles about

  1. python Error collection

    1.lt And list equivalent , Can't be a variable name 2. Chinese pathname :os.path.normcase(filepath) If you encounter ascii The code cannot be converted somewhere in the path , that filepath.encode('gbk ...

  2. [python]python Error collection

    ValueError: invalid literal : '' You cannot convert a non numeric string to an integer object has no attribute Object calls a method that doesn't have ( Built in or custom ) TypeError ...

  3. 【 machine learning Machine Learning】 Data collection

    Yesterday, I summarized the materials of deep learning , Today, let's summarize the information of machine learning ( Friendship tips : Some websites need " Science and the Internet "^_^) Recommend some good books : 1.Pattern Recognition and Machi ...

  4. Python: A collection of common mistakes ( Continuous updating ing)

    Beginners Python, It's easy to go through all kinds of mistakes . Through the collection , Can quickly find the cause of the error and solutions . 1.IndentationError:expected an indented block Explain that we need to abbreviate here ...

  5. Python in os and shutil Module practical method collection

    Python in os and shutil Module practical method collection type : Reprint Time :2014-05-13 This article mainly introduces Python in os and shutil Module practical method collection , Friends in need can refer to Copy the code as follows : ...

  6. Python Develop interview highlights

    I'm working on a set of python Interview development collection , Can help star once , thank you ! Address :GitHub special column

  7. Become a video Analyst : Automatically generate video highlights (Python Realization )

    Introduce I'm a super cricket fan . Since I remember , I'm crazy about this sport , It still plays an important role in my daily life . I believe many people who read this article will nod their heads ! But since I started working , It's hard to keep up with all the games . I can't ...

  8. python Company interview questions python Interview questions

    Question 1 : What the output of the following code will be ? Say your answer and explain . class Parent(object): x = 1 class Child1(Parent): pass class Child2(Par ...

  9. Python A collection of usage of some methods

    1.range() Method : >>>range(5) [0, 1, 2, 3, 4] >>>a= ["heke","sdsdjs" ...

  10. Python Full stack learning _ Homework collection ( Continuous updating )

    python Basics day1 python First time to know . Fundamentals of computer (cpu, Memory , Hard disk , operating system ) . Python Born in application . python The history of . Programming language classification . python Advantages and disadvantages . pyth ...

Random recommendation

  1. div The middle way

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Oracle database Restart

    Get into server after su - oracle lsnrctl stop sqlplus / as sysdba shutdown immediate; quit lsnrctl start sqlplu ...

  3. Red and black trees ( 5、 ... and ) And Java The implementation of the

    Summary The theoretical knowledge of red black tree is introduced in the front . Mangrove C Language and C++ The implementation of the . This chapter introduces the characteristics of the red black tree Java Realization , If readers are not familiar with the theoretical knowledge of red black tree , First, learn the theoretical knowledge of red black tree , Let's go back to this chapter . It's the same old saying , Mangrove C/C+ ...

  4. oracle See the relevant user table

    select TABLE_NAME from user_tables  // Current user table select TABLE_NAME from dba_tables  // All user tables + The system tables select TA ...

  5. hdu 4057(ac automata + State compression dp)

    The question : Easy to understand ... analysis : The maximum number of pattern strings given in the title is 10 individual , So I thought of using state compression dp To do it , Its state range is 1-2^9, So the biggest is 2^10-1, Then we can use :dp[i][j][k] The length is i, stay tri ...

  6. linux c++ Traverse the file name in a directory ( Include the file name of the subdirectory )

    Recently, there is a requirement to traverse every file in the directory and get the absolute path of the file , We know linux c++ There is system So I'm in the code Sir has become a log, And then read log Each line of the file name , And then store it ...

  7. python Environment building --pycharm Installation and use of

    Learning website : -- Novice tutorial (2.0 and 3.0) http://www.runoob.com/python/python-tutorial.html http://www.runoob.com/python ...

  8. Native js timer

    Be free and at leisure , Write a simple timer <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  9. Learn Python The Hard Way, 2nd Edition

    After reading the book , You decide to continue programming . Maybe it can be a career for you , Maybe it can be a hobby for you . But you need some guidance , Make sure you don't go the wrong way , Or help you get the most out of this new hobby . I've been programming for a long time . You've been imagining for a long time ...

  10. Jizhong OJ 2019.01.25【NOIP Improvement group 】 simulation B Group T2 The numbers are right

    Statement The numbers are right Time Limits: 2000 ms    Memory Limits: 262144 KB Description Small H He is a student who is good at thinking , Now she's thinking about a sequence .  ...