简体   繁体   English

我试图创建我的第一个数据库,但出现错误

[英]I tried to make my first database and I got error

I just started learning MySql for Python on W3Schools.我刚开始在 W3Schools 上为 Python 学习 MySql。 I copied the code that was given as an example and I run it in IDLE, but I got an error.我复制了作为示例给出的代码并在 IDLE 中运行它,但出现错误。

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="myusername",
  passwd="mypassword"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")

Here is the full traceback:这是完整的回溯:

  File "C:\Users\risto\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\network.py", line 509, in open_connection
    self.sock.connect(sockaddr)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/risto/AppData/Local/Programs/Python/Python37-32/mysql1.py", line 6, in <module>
    passwd="mypassword"
  File "C:\Users\risto\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "C:\Users\risto\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "C:\Users\risto\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
    self._open_connection()
  File "C:\Users\risto\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 206, in _open_connection
    self._socket.open_connection()
  File "C:\Users\risto\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\network.py", line 512, in open_connection
    errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it)

Can someone help me?有人能帮我吗?

the service about MySQL is not running, or filtered by some firewall rule.关于 MySQL 的服务未运行,或被某些防火墙规则过滤。
Check it out一探究竟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想制作一个自动加入我的课程的类型机器人我已经尝试过但得到了错误 - I want to make a type bot which will join my classes automatically i have tried it but got the error 我查询我的 sqlite 数据库并得到结果为 [ ](空白),即使我的数据库有我试图查询的数据 - I query my sqlite database and got the result as [ ] (blank) even when my database has the data I tried to query 当我尝试在我的 cmd 中安装 pandas 时,我收到了他的错误 - when i tried to install pandas in my cmd i got his error 当我尝试在 python 中创建浏览器时出现错误 - I got an error when I tried to create a browser in python 当我尝试安装 sacrebleu 时,出现安装错误 - When I tried to install sacrebleu, I got an installation error 我尝试使用 pip 安装软件包,但出现此错误 - I tried to install packages using pip but i got this error 我试图将我的文件夹推送到 Heroku 并收到以下消息 - I tried to push my folder to Heroku and got the below msg 我尝试安装 pyinstaller 并得到了这个 - i tried to install pyinstaller and got this 试图运行 make 命令,但得到了这个错误 - Tried to run the make command but got this error instead 我尝试使用 skulpt 制作 python 解释器,但遇到了意外错误。 我想在我的网站上使用它 - I tried to make a python interpreter using skulpt, but ran into an unexpected error. I want to use it on my website
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM