运行 SQL, 进不去

Running SQL, cannot get into

我想使用 Python?

将检索到的数据存储在笔记本电脑中我选择的数据库中

有没有设置和连接?

我做过:

pip install mysql.connector

以下:Python MySQL - CodersLegacy[^]

我试过之后:

import mysql.connector
 
check = mysql.connector.connect(
    host= 'localhost',
    user = 'root',
    password = '12345678')
 
print(check)

它给我错误:

---------------------------------------------------------------------------
InterfaceError                            Traceback (most recent call last)
<ipython-input-4-e72118a94c51> in <module>()
      3 check = mysql.connector.connect(
      4     host= 'localhost',
----> 5     user = 'root')
      6 
      7 

C:\Users\id\AppData\Local\Continuum\anaconda2\lib\site-packages\mysql\connector\__init__.pyc in connect(*args, **kwargs)
    177         return CMySQLConnection(*args, **kwargs)
    178     else:
--> 179         return MySQLConnection(*args, **kwargs)
    180 Connect = connect  # pylint: disable=C0103
    181 

C:\Users\id\AppData\Local\Continuum\anaconda2\lib\site-packages\mysql\connector\connection.pyc in __init__(self, *args, **kwargs)
     93 
     94         if len(kwargs) > 0:
---> 95             self.connect(**kwargs)
     96 
     97     def _do_handshake(self):

C:\Users\id\AppData\Local\Continuum\anaconda2\lib\site-packages\mysql\connector\abstracts.pyc in connect(self, **kwargs)
    714 
    715         self.disconnect()
--> 716         self._open_connection()
    717         self._post_connection()
    718 

C:\Users\id\AppData\Local\Continuum\

问题可能是因为您的连接器没有指定您要连接的数据库的名称。该代码在其他方面也能正常工作,但您可能想尝试一下。 例如:

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="12345678", 
  database="name_of_your_database"
)
print(mydb)