GithubHelp home page GithubHelp logo

pymysql / myloginpath Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 13.0 19 KB

MySQL's login path file reader

Home Page: https://pypi.org/project/myloginpath/

License: MIT License

Makefile 1.48% Python 98.52%
mysql python

myloginpath's Introduction

Documentation Status codecov

PyMySQL

This package contains a pure-Python MySQL client library, based on PEP 249.

Requirements

  • Python -- one of the following:
  • MySQL Server -- one of the following:

Installation

Package is uploaded on PyPI.

You can install it with pip:

$ python3 -m pip install PyMySQL

To use "sha256_password" or "caching_sha2_password" for authenticate, you need to install additional dependency:

$ python3 -m pip install PyMySQL[rsa]

To use MariaDB's "ed25519" authentication method, you need to install additional dependency:

$ python3 -m pip install PyMySQL[ed25519]

Documentation

Documentation is available online: https://pymysql.readthedocs.io/

For support, please refer to the StackOverflow.

Example

The following examples make use of a simple table

CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `email` varchar(255) COLLATE utf8_bin NOT NULL,
    `password` varchar(255) COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
AUTO_INCREMENT=1 ;
import pymysql.cursors

# Connect to the database
connection = pymysql.connect(host='localhost',
                             user='user',
                             password='passwd',
                             database='db',
                             cursorclass=pymysql.cursors.DictCursor)

with connection:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
        cursor.execute(sql, ('[email protected]', 'very-secret'))

    # connection is not autocommit by default. So you must commit to save
    # your changes.
    connection.commit()

    with connection.cursor() as cursor:
        # Read a single record
        sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
        cursor.execute(sql, ('[email protected]',))
        result = cursor.fetchone()
        print(result)

This example will print:

{'password': 'very-secret', 'id': 1}

Resources

License

PyMySQL is released under the MIT License. See LICENSE for more information.

myloginpath's People

Contributors

methane avatar nickodell avatar renovate[bot] avatar singhujjwal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

myloginpath's Issues

ERROR if --login-path contains definition for socket

pymysql.connect does not know what 'socket' is and it instead expects to get 'unix_socket'...

Run command at the bash prompt:

mysql_config_editor set --login-path=testProfile1 --socket=/tmp/mysql.sock --host=localhost --user=me --password

Python code snippet

import myloginpath
import pymysql
conf = myloginpath.parse('testProfile1')
conf['unix_socket'] = conf.pop('socket')
con = pymysql.connect(**conf, db = sql_database)

IF the line conf['unix_socket'] = conf.pop('socket') is left out, get the error:

TypeError: init() got an unexpected keyword argument 'socket'

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/test.yaml
  • actions/checkout v4
  • actions/setup-python v5
  • codecov/codecov-action v4
  • actions/upload-artifact v4
pep621
pyproject.toml
pip_requirements
requirements.txt

  • Check this box to trigger a request for Renovate to run again on this repository

A port of myloginpath for R

I wanted to use this library in R, so I ported it into to R. I gave it the highly original name of rmyloginpath. It's under the same license as this project, and the API is pretty much identical. Would you mind linking to my project?

Anyhow, thanks for the library!

Idea for a simpler way

Just parse the output from my_print_defaults

me@ubuntu:~$ my_print_defaults --show client
--user=me
--password=password
--host=localhost

mysql_config_editor emits config file with quotes

I've recently been running into an issue where mysql_config_editor will emit a configuration file which includes quotes. myloginpath interprets the quotes as part of the value.

This issues is caused by using MySQL 8.0.24, which came out on 2021-4-20. Here's the relevant part of the changelog:

To enable use of spaces and other special characters within configuration values, mysql_config_editor now surrounds values it writes to the configuration file with double quote characters, and also escapes double quote characters used within values. (Bug #19953349, Bug #74691)

https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-24.html

Here's an example session:

$ mysql_config_editor --version
mysql_config_editor  Ver 8.0.25-0ubuntu0.20.10.1 for Linux on x86_64 ((Ubuntu))
$ mysql_config_editor set --login-path=test --host=foo
$ mysql_config_editor print --login-path=test
[test]
host = "foo"
$ python3                 
Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import myloginpath
>>> myloginpath.parse('test')
{'host': '"foo"'}

_get_login_path_file uses getenv() instead of os.getenv() (typo?)

Problem:

  File "backup.py", line 20, in __init__
    self.path = myloginpath.parse(path)
  File "C:\Users\user\project\.env\lib\site-packages\myloginpath.py", line 35, in parse
    path = _get_login_path_file()
  File "C:\Users\user\project\.env\lib\site-packages\myloginpath.py", line 53, in _get_login_path_file
    file_path = os.path.join(getenv("APPDATA"), "MySQL", ".mylogin.cnf")
NameError: name 'getenv' is not defined

Fix:

52 if sys.platform == "win32":
53        file_path = os.path.join(os.getenv("APPDATA"), "MySQL", ".mylogin.cnf")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.