MySQL Connection Error resolution

Source: Internet
Author: User

Situation One:

BUG: Error 1044 (42000): Access denied for user "@ ' localhost ' to database ' MySQL '

MySQL database in the user table, there is a username is empty account is anonymous account, resulting in the log in when the use of root, but the actual anonymous login, through the error message "@" localhost can be seen.

Workaround: Reference

1. Turn off MySQL
[[Email protected] ~]# service mysqld Stop
2. Blocking Permissions
[email protected] ~]# Mysqld_safe--skip-grant-table
screen appears: Starting demo from ... ..
3. Start a new terminal input
[[email protected] ~]# mysql-u root MySQL
mysql> Delete from user where user= ';
mysql> FLUSH privileges; Be sure to write, otherwise if you close the previous terminal, the original error will occur
mysql> \q

Situation Two:

I want to remove a table from MySQL by Flask_sqlalchemy, but Flask_sqlalchemy only Db.drop_all ()

Now find a way to use Flask_sqlalchemy and pymysql for remote operation

Use Pymysql directly to delete a table operation:

#-*-coding:utf-8-*-#!/usr/bin/env python#@Author: Tianbao#@Contact: [email protected]#@Time: 2018/5/13 9:55#@File: pymysql_del_preview.py#@Software: PycharmImportPymysqlconnect= Pymysql.connect (#connecting to the database serverUser="Root", Password="Root", host="205.266.87.91", Port=3306, DB="movie", CharSet="UTF8") Conn= Connect.cursor ()#Create an action cursorConn.execute ("SELECT * from user")#Select View your own user This table (to see the tables in your database first use XX and then view)rows = Conn.fetchall ()#Fetchall (): Receives all the returned result rows, if not, returns the number of contents of the table int type forIinchrows:Print(i) Conn.execute ("drop table Preview") Conn.close ()#closing a cursor connectionConnect.close ()#Close the database server connection to free up memory

  Regenerated into the original table by Flask_sqlalchemy

#-*-coding:utf-8-*-#!/usr/bin/env python#@Author: Tianbao#@Contact: [email protected]#@Time: 2018/5/13 9:34#@File: flask_sqlalchemy_create_preview.py#@Software: Pycharm fromFlaskImportflask,render_template fromFlask_sqlalchemyImportSQLAlchemy fromDatetimeImportDatetimeapp= Flask (__name__) app.config['Sqlalchemy_database_uri'] ="Mysql+pymysql://root:[email Protected]:3306/movie"app.config['sqlalchemy_track_modifications'] =trueapp.config['Secret_key'] ="HelloWorld"DB=SQLAlchemy (APP)#Release NoticeclassPreview (db. Model):__tablename__='Preview'ID= db. Column (db. integer,primary_key=True) Title= db. Column (db. String (255), unique=True) Logo= db. Column (db. String (255), unique=true)#coverAddtime = db. Column (db. DateTime, Index=true, default=DateTime.Now)def __repr__(self):return '<preview%s>'%Self.titleif __name__=='__main__': Db.create_all ()#Db.drop_all ()    #role = Role (    #name= ' Super admin ',    #auths= "    # )    #From werkzeug.security import Generate_password_hash    #admin = admin (    #name= ' Imoocmovie1 ',    #pwd=generate_password_hash (' Imoocmovie1 '),    #is_super=0,    #roleid=1,    # )    #db.session.add (Admin)    #Db.session.commit ()    #Pass

MySQL Connection Error resolution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.