美文网首页小白学python
python3上安装mysql时遇到的问题总结

python3上安装mysql时遇到的问题总结

作者: Mayxz | 来源:发表于2019-07-31 20:03 被阅读0次

    1、python3上安装pymysql连接mysql数据库报错时,修改_init_.py添加以下配置即可

    import pymysql

    pymysql.install_as_MySQLdb()

    2、安装 MySQLdb 库

    安装 mysql-connector-python:pip3 install mysql-connector-python

    安装 mysqlclient:pip3 install mysqlclient

    检查 MySQLdb 是否安装成功:python3 -c "import MySQLdb"没有报错,安装成功

    3、如图,在使用命令pip3 install mysqlclient  进行安装时,报错如下

    解决方法按照下方进行操作可解决:

    $ brew install mysql-connector-c   

    $ pip3 install mysqlcient # 报错找不到OSError: mysql_config not found

    $ cd /usr/local/Cellar/mysql-connector-c/6.1.11/bin

    $ cp mysql_config mysql_config.bak  备份

    $ chmod u+w mysql_config # 文件114行从libs="$libs -l "修改为libs="$libs -lmysqlclient -lssl -lcrypto"

    $ pip3 install mysqlcient

    以上方法不行的话,可尝试以下方式:

    去mysql官网,下载

    http://dev.mysql.com/downloads/mysql/

    mysql并且安装

    安装完成后,打开终端,输入下方语句修改环境变量:

    PATH="$PATH":/usr/local/mysql/bin

    好了,现在重启终端,并输入

    pip install mysql-python

    ---------------------

    4、python3上解决报错Access denied for user 'root'@'localhost' (using password: YES)")

    出现以上原因基本上是由于数据库配置的时候 密码忘记原因导致,解决方式如下(来源于网上):

    第一步:如果mysql服务正在进行,先从系统偏好设置里 把 mysql 将之停止。

    第二步:在终端中以管理员权限启动mysqld_safe,命令如下:sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

    执行结果如下:2016-06-12T08:29:17.6NZ mysqld_safe Logging to'/usr/local/mysql/data/lyqdeMacBook-Pro.local.err'.2016-06-12T08:29:17.6NZ mysqld_safe Starting mysqld daemon with databasesfrom/usr/local/mysql/data

    第三步:不要关闭当前的终端窗口,新建一个终端窗口,输入如下命令/usr/local/mysql/bin/mysql,回车登录mysql

    登录后,看到欢迎信息:

    Welcome to the MySQL monitor. Commands end with ; or \g.

    Your MySQL connection id is 3

    Server version: 5.7.19 MySQL Community Server (GPL)

    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

    Oracle is a registered trademark of Oracle Corporation and/or its

    affiliates. Other names may be trademarks of their respective

    owners.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql>

    打开"mysql"这个数据库,SQL如下:mysql> use mysql;

    看到结果:You can turn off thisfeature togeta quicker startup with -A

    Database changed

    mysql>

    然后,更新root的密码,SQL如下:

    mysql> update usersetauthentication_string=password('123456')whereHost='localhost'and User='root';

    执行结果如下:Query OK,1row affected,1warning (0.01 sec)

    Rows matched: 1Changed:1Warnings:1

    退出mysql(执行sql语句:exit)

    最后一步:将mysqld_safe进程杀死,重启mysqld。

    登录mysql

    /usr/local/mysql/bin/mysql -uroot -proot

    这个时候,如果执行查询之类的操作,比如执行"show databases;",可能会有如下提示:

    ERROR1820(HY000): You must reset your passwordusingALTER USER statement before executingthisstatement

    根据提示进行操作,输入如下SQL语句,这个语句的作用是修改root用户的口令为root:

    mysql> alter user'root'@'localhost'identified by'root';

    结果

    Query OK,0rows affected。

    5、执行 python3 manage.py 报错如下

    原因:提示你的mysqlclient版本过低

    解决附下图

    相关文章

      网友评论

        本文标题:python3上安装mysql时遇到的问题总结

        本文链接:https://www.haomeiwen.com/subject/mtlxdctx.html