Jump to content

Recommended Posts

Posted

Hi,

I am using pycharm to execute my program, I am getting following error:

Quote

/home/PycharmProjects/pythonProjectRev/venv/bin/python /home/zulfi/PycharmProjects/pythonProjectDB/main.py
Traceback (most recent call last):
  File "/home/PycharmProjects/pythonProjectDB/main.py", line 9, in <module>
    cursorclass=pymysql.cursors.DictCursor)
  File "/home/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py", line 353, in __init__
    self.connect()
  File "/home/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py", line 633, in connect
    self._request_authentication()
  File "/home/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py", line 907, in _request_authentication
    auth_packet = self._read_packet()
  File "/home/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "/home/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/home/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")

Process finished with exit code 1

Following is my code:

import pymysql.cursors

# con = pymysql.connect('zulfi'@'localhost' (password: NO))
conn = pymysql.connect(host='localhost',
                       user='root',
                       password='',
                       database='db',
                       charset='utf8mb4',
                       cursorclass=pymysql.cursors.DictCursor)

I have created "db" database in mysql:

Quote

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db                 |
| menagerie          |
| mysql              |
| performance_schema |
| pets               |
| sys                |
+--------------------+
7 rows in set (0.00 sec)

 

Somebody please guide me.

 

Zulfi.

Posted (edited)

What you get when you use:

select * from mysql.user;

?

 

Has this ever worked with Python, or is this your first time using MySQL with your own Python code?

 

BTW, careful with "localhost". "localhost" on machines with enabled IPv6 can mean ::1, otherwise 127.0.0.1

e.g. if I in command-line use ping localhost, I see it resolves to ::1

 

Windows firewall checked/disabled?

 

Edited by Sensei
Posted (edited)

@SenseiHi,

Thanks for your response. I think I am getting garbage:

Quote

mysql> select * from mysql.user;
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| Host      | User             | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin                | authentication_string                     | password_expired | password_last_changed | password_lifetime | account_locked |
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| localhost | root             | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | auth_socket           |                                           | N                | 2022-02-18 23:31:30   |              NULL | N              |
| localhost | mysql.session    | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | Y          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                | 2022-02-18 23:31:31   |              NULL | Y              |
| localhost | mysql.sys        | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                | 2022-02-18 23:31:31   |              NULL | Y              |
| localhost | debian-sys-maint | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password | *71C983FDE1D933E8A278D729FC2F45DAC1CDA37E | N                | 2022-02-18 23:31:32   |              NULL | N              |
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+

When I use ping localhost, my output is:

Quote

$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.064 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.066 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.058 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.065 ms
^C

This is the first time, I am executing mysql with Python.

I am working on Ubuntu 18.04.

Somebody please guide me.

 

Zulfi.


4 rows in set (0.00 sec)

mysql>

 

Edited by zak100
Posted (edited)
1 hour ago, zak100 said:

I think I am getting garbage:

Copy it into a text editor that allows horizontal scrolling, and you'll see it's not garbage.

  

1 hour ago, zak100 said:

I am working on Ubuntu 18.04.

I am working on Windows and using XAMPP.

The differences between what I have here and what you have are small.

I have a "Password" column that is blank in all rows, which is not in your log...

I have multiple "root" user accounts, each for IPv4 and IPv6, either by name or directly by IP number.

1416562970_Grab1.thumb.png.b4ec71c0e17947bc169edb446808c834.png

 Have you tried the phpmyadmin from a web browser?

 

Different MySQL versions can behave slightly differently.

 

So if I were you, I would try inserting a password column in mysqladmin/phpmyadmin,

and then duplicate the row to have IPv6 support as well, just in case. Just like in my screenshot above.

 

Edited by Sensei
Posted

Hi,

I followed the link but I am getting error in creating user:

mysql> create user 'pyuser'@'localhost';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>

 

Somebody please me.

Posted
18 hours ago, zak100 said:

I followed the link but I am getting error in creating user:

mysql> create user 'pyuser'@'localhost';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>

Use:

SHOW VARIABLES LIKE 'validate_password%';

to learn what is validate_password_policy value.

Then set it by:

mysql> SET GLOBAL validate_password_policy=LOW;
OR
mysql> SET GLOBAL validate_password_policy=0;

Then you should be able to set low quality passwords for new users (not recommended for a real server).

  • 2 weeks later...
Posted

@Sensei Hi,

I am able to create a user:

mysql> create user 'pyuser2'@'localhost'identified by 'pyuser22'
    -> ;
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES on mysql.* to 'pyuser2'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> 

Please guide me what should be the next step.

 

Zulfi.

  • 2 months later...
Posted
On 4/14/2022 at 11:12 PM, zak100 said:

@Sensei Hi,

I am able to create a user:

mysql> create user 'pyuser2'@'localhost'identified by 'pyuser22'
    -> ;
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES on mysql.* to 'pyuser2'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> 

Please guide me what should be the next step.

 

Zulfi.

Haven't you been using mysql for 10 yrs now?

https://www.linuxquestions.org/questions/linux-newbie-8/creating-a-database-using-a-new-user-in-mysql-4175431471/

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.