Я пытаюсь использовать mysql для запуска python - flask веб-приложения. Я подключаюсь к базе данных в основном файле приложения, однако каждый раз, когда я пытаюсь ввести данные в базу данных (т.е. зарегистрировать клиента), я получаю сообщение об ошибке:
Traceback (most recent call last):
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/<username>/.local/lib/python2.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/mnt/c/Users/<username>/Documents/<web application>/app.py", line 156, in register
cur = mysql.connection.cursor()
File "/home/<username>/.local/lib/python2.7/site-packages/flask_mysqldb/__init__.py", line 94, in connection
ctx.mysql_db = self.connect
File "/home/<username>/.local/lib/python2.7/site-packages/flask_mysqldb/__init__.py", line 81, in connect
return MySQLdb.connect(**kwargs)
File "/home/<username>/.local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/home/<username>/.local/lib/python2.7/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
Я смотрел похожие статьи с основное предложение:
(in sql)
USE mysql;
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User='root';
flush privileges;
exit;
(in terminal): sudo service mysql restart
Как я настраиваю базу данных:
# Config MySQL
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = '<root password>'
app.config['MYSQL_DB'] = '<db name>'
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
#init MYSQL
mysql= MySQL(app)
Однако ошибка все еще сохраняется после попытки этого. Я не уверен, как продолжить, поэтому любая помощь будет оценена.