I wanted to create a little authentication system using python/flask on linux (Fedora).
I chose MySQL as the main database, created a user table then quit with exit
.
Then when I run my program I get this error :
OperationalError: (1045, u"Access denied for user 'root'@'localhost' (using password: YES)")
So I tried to access to the database and try to fix it but I just can't get access to MySQL.
I tried all the commands and all the solutions that I found on many web pages(including those that are here) and nothing seem to work. Whether it's mysql -u root -p
or sudo mysql...
or even mysqladmin
, I just get the same error over and over again.
OperationalError: (1045, u"Access denied for user 'root'@'localhost' (using password: YES)")
A lot of the solutions that were provided were for Ubuntu, using even commands like dpkg reconfigure
and stuff like that which doesn't work for me.
I don't even have the permission to write in /etc/my.cnf.
Here is my code in case you need it (in views.py
):
from app import mysql
@app.route("/Authenticate")
def Authenticate():
username = request.args.get('UserName')
password = request.args.get('Password')
cursor = mysql.connect().cursor()
cursor.execute("SELECT * from User where Username='" + username + "' and Password='" + password + "'")
data = cursor.fetchone()
if data is None:
return "Username or Password is wrong"
else:
return "Logged in successfully"
And (in __init__.py
):
mysql = MySQL()
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = 'root'
app.config['MYSQL_DATABASE_DB'] = 'EmpData'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)