0

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)
davidism
  • 121,510
  • 29
  • 395
  • 339
Draga
  • 23
  • 9
  • please visit here [https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost](https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost) – Manjeet Thakur Nov 13 '17 at 11:36
  • This is why I wrote "I don't even have the permission to write in /etc/my.cnf." Already did. – Draga Nov 13 '17 at 11:42
  • there is no other way in my knowledge. – Manjeet Thakur Nov 13 '17 at 11:44
  • I found a way to modify it thanks to this : https://stackoverflow.com/questions/11632733/mysql-editing-saving-my-cnf-file, but I can't start or restart mysql. When I use `service mysql start` I get this error > Failed to start mysql.service: Unit mysql.service not found. Same thing happens with `stop` and `restart`. – Draga Nov 13 '17 at 12:26

0 Answers0