Answer the question
In order to leave comments, you need to log in
MAC and local MySQL database in python?
I have a MacOS computer and I wrote a python program using pymysql module and a local MySQL database running on MAMP, and while executing this program, I encountered the following problem/error:
(2003, "Can't connect to MySQL server on ' localhost' ([
Errno 61] Connection refused)")
import pymysql.cursors
def connection():
connection = pymysql.connect(host='localhost', user='root', password='root', db='datebase1', cursorclass=pymysql.cursors.DictCursor)
return connection
def proverka():
connect = connection()
try:
with connect.cursor() as cursor:
cursor.execute(f"CREATE TABLE `test`("
" `id` INT NOT NULL AUTO_INCREMENT,"
" `uid` INT NOT NULL,"
" `nick` varchar(255) NOT NULL DEFAULT 'null',"
" PRIMARY KEY (`id`)) ENGINE=InnoDB")
connect.commit()
return 'Таблица \'test\' создана'
finally:
connect.close()
print(proverka())
Answer the question
In order to leave comments, you need to log in
Don't use localhost. Why is dealt with directly on an example with MySQL: an example of a problem with localhost .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question