pymysql 安装的坑

2019-06-04  本文已影响0人  lifeLL
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 61] Connection refused)")

初判断mysql没启动,果然:
31559662690_.pic.jpg 41559662939_.pic.jpg 51559662958_.pic.jpg 61559663001_.pic.jpg 71559663015_.pic.jpg
以为这样可以了,不料又来新问题
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

待续 。。。

开启服务 
sudo mysql.server start
设置密码
mysqladmin -uroot password "xxxxxx"  #xxxxxx为设置密码

提示
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

进入
mysql -uroot -p密码

提示
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.16 Homebrew

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit

connect时候,设置了数据库database = 'crawler',报错如下
pymysql.err.InternalError: (1049, "Unknown database 'crawler'")

待续。。。

创建个数据库
 cursor.execute("CREATE DATABASE spiders DEFAULT CHARACTER SET utf8")

db = pymysql.connect(host='localhost',user = 'root',password = 'xxxxxx')
        cursor = db.cursor()
        cursor.execute('SELECT VERSION()')
        data = cursor.fetchone()
        print('Database version:',data)
        cursor.execute("CREATE DATABASE spiders DEFAULT CHARACTER SET utf8")
        cursor.close()
        db.close()
果然多了个spiders
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| crawler            |
| information_schema |
| mysql              |
| performance_schema |
| spiders            |
| sys                |
+--------------------+
mysql> show tables from crawler;
+-------------------+
| Tables_in_crawler |
+-------------------+
| crawler_hub       |
| students          |
+-------------------+

新问题  
    self.db = leveldb.LevelDB(self.name)
leveldb.LevelDBError: IO error: lock gzsina.urldb/LOCK: Resource temporarily unavailable
解决方案 
把对应生成的文件删掉就可以
待续。。。
连接不上图形化数据工具
mysql> use mysql;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

删除表
use crawler;

mysql> DROP TABLE crawler_hub ;

mysql> show tables from crawler;
上一篇下一篇

猜你喜欢

热点阅读