Reputation: 1
I was trying to connect the mysql with python.
import mysql.connector
db = mysql.connector.connect()
Uptill this point everything was fine. But after this when I started specifying the attributes of the connect command, using the code bellow
import mysql.connector
db = mysql.connector.connect(
host = "localhost", #specifies the host computer(in this case this computer only)
user = "root", #specifies the user
passwd = "<my password was here>"
)
this error came up on running the code,
Traceback (most recent call last):
File "C:/Users/Co-valent Cyclist/Desktop/Python + MySQL/test 1.py", line 6, in <module>
passwd = "co_valent_bonds"
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\__init__.py", line 177, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 104, in __init__
self.connect(**kwargs)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 785, in connect
self._post_connection()
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 757, in _post_connection
self.set_charset_collation(self._charset_id)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 716, in set_charset_collation
charset_name, collation_name))
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 970, in _execute_query
self.cmd_query(query)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 590, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 478, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1115 (42000): Unknown character set: 'utf8mb4'
how do I rectify this? Please help me out. Thanks!!
Upvotes: 0
Views: 2337
Reputation: 11
Use charset="utf8" while creating the connection object .
If your characters actually use the superset utf8mb4 then this may cause problems, but if not, then this should work!
import mysql.connector
db = mysql.connector.connect(
host = "localhost", #specifies the host computer(in this case this computer only)
user = "root", #specifies the user
passwd = "<my password was here>",
charset = "utf8"
)
Upvotes: 1