I have MySQL Workbench installed in my local machine. I want to simultaneously fetch my SQL workbench data in Colab. So that I can apply ML algorithms on that. I am using this code,
import mysql.connector
import pandas as pd
user = 'XXXX'
password = 'XXXXXXX'
host = 'XXXXabcWW'
port = 'XXXXXXCV'
dbname = 'XXXX'
conn = mysql.connector.connect(user=user, password=password, host=host, database=dbname, port=port)
df = pd.read_sql("SELECT \* FROM table_name", conn)
print(df)
But is not getting connected.
I am getting error as Can't connect to MySQL server on 'XXXXabcWW'
How to correct it? TIA
You can connect mysql workbrench like this in google colab, make sure username, password, hostname & db name is correct
import mysql.connector
conn = mysql.connector.connect(user='username', password='password',
host='hostname', database='dbname')
cursor = conn.cursor()
query = 'SELECT * FROM table_name'
cursor.execute(query)
result = cursor.fetchall()
cursor.close()
conn.close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.