G
G
Guerro692020-06-18 11:33:59
MySQL
Guerro69, 2020-06-18 11:33:59

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())


If anything I checked, phpmyadmin itself was definitely on.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sundukov, 2020-06-18
@alekciy

Don't use localhost. Why is dealt with directly on an example with MySQL: an example of a problem with localhost .

A
asakasinsky, 2020-06-18
@asakasinsky

Replace "localhost" with 127.0.0.1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question