is it possible to connect to a local database file on pymysql ?

259 views
Skip to first unread message

lator

unread,
Jun 13, 2022, 10:43:15 AM6/13/22
to PyMySQL Users
I exported my database from phpMyAdmin and I'm using it for a project. In my connection line, I put:
                connection = pymysql.connect("database/my_db.sql")
and it was throwing a positional argument error, so I figured from StackOverflow that you have to use keyword arguments for pymysql to work properly so now I want to know if it's feasible to use a local db file.
Because, the arguments are usually, localhost, user, password and the likes.
When I tried to use the 'database' keyword as in:
       connection = pymysql.connect(database="database/my_db.sql")
I got an error talking about localhost denial access and all. And to be fair, the db file is not on the localhost.


Jay Summet

unread,
Jun 13, 2022, 2:58:04 PM6/13/22
to pymysq...@googlegroups.com
You can definitely use pymysql to connect to a database SERVER on the
local machine. (You would typically use "localhost" or "127.0.0.1" to
indicate that the IP address of the database server is on the same
machine as the client).

However, pymysql does not natively open database files, so you would
also have to install/run a mysql database server locally.

If you just want to use a local file as a database, the sqlite3 module
is probably a better choice than pymysql.

https://www.summet.com/dmsi/html/database.html#using-a-local-sql-database-sqlite3


Jay

On 6/13/22 10:43, lator wrote:
> I exported my database from phpMyAdmin and I'm using it for a project.
> In my connection line, I put:
> *connection = pymysql.connect("database/my_db.sql")*
> and it was throwing a positional argument error, so I figured from
> StackOverflow that you have to use keyword arguments for /pymysql/ to
> work properly so now I want to know if it's feasible to use a local db file.
> Because, the arguments are usually, /localhost/, /user/, /password/ and
> the likes.
> When I tried to use the 'database' keyword as in:
> *connection = pymysql.connect(database="database/my_db.sql")*
> I got an error talking about localhost denial access and all. And to be
> fair, the db file is not on the localhost.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "PyMySQL Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pymysql-user...@googlegroups.com
> <mailto:pymysql-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pymysql-users/82c625da-d3a1-41eb-8ce7-df0a374df22dn%40googlegroups.com
> <https://groups.google.com/d/msgid/pymysql-users/82c625da-d3a1-41eb-8ce7-df0a374df22dn%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages