Exception errors when closing server - mysql

I'm fairly new to django and have been following the tutorial/documentation, got to the point where I am supposed to set up the server. I am using Ubuntu and have mysql 5.5 server installed with python3.4, pip etc. So I went through the steps of setting up the database and server using mysql-connector-python, I added the south app as well to django settings and everything works, I can run the server, view the django congrats page, but the trouble is when I close the server in the terminal, ctrl C, an Error gets thrown.
Exception ResourceWarning: ResourceWarning('unclosed <socket.socket object, fd=9, family=2, type=1, proto=6>',) in <socket.socket object, fd=9, family=2, type=1, proto=6> ignored
Not sure where to fix the problem. Do I have the write close connection somewhere.

I get the same messages but I don't care because probably I can do nothing.
I think this connections are opened by Django and Django should do something with this, not me.
But normally servers work all the time without stops and maybe nobody cares about unclosed socket.

Related

Flask Security Too Mysql connection problem

I'm using Flask Security Too (https://flask-security-too.readthedocs.io/en/stable/index.html) to authenticate users on a test server. I followed the instructions in the documentations to get it up and running. It all works perfect, however for some reason the application is losing the connection to the MySQL server and starts returning an Internal Server Error. In Sentry I see the following error message:
(sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
[SQL: SELECT anon_1.user_id AS anon_1_user_id, anon_1.user_email AS anon_1_user_email, anon_1.user_first_name AS anon_1_user_first_name, anon_1.user_last_name AS anon_1_user_last_name, anon_1.user_password AS anon_1_user_password, anon_1.user_last_login_at AS anon_1_user_last_login_at, anon_1.user_current_login_at AS anon_1_user_current_login_at, anon_1.user_last_login_ip AS anon_1_user_last_login_ip, anon_1.use...
This error usually appears when the site has not been accessed for several hours during night. Restarting the Flask app solves the problem.
I tried changing the SqlAlchemy options, without success. Since I'm using a MySQL database on a dedicated server I also tried using a local MySQL database, I'm having the same issue here.
I would like to solve this issue before spending more time on integrating this into my website.
Does anyone know what can cause this problem?
I have seen this (and there have been bugs) when using psycopg2 - where a PRIOR error (such as select on a column with an incompatible type - causes the connection to permanently be unusable. From my testing - there wasn't an obvious way to even know this had happened until the query that throws this error - since it was a coding error - I fixed a few bugs in that area. Note that was with psycopg2 - which I don't think you are using.
I would look at logs or turn on complete mysql query logging to look at what might be querying it during the evening.
Another thought - which I don't think would cause THIS error - is that many DBs drop connections after some period of time out. Make sure you are using Flask-SQLAlchemy 2.4.0 or greater and put in the config:
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"pool_pre_ping": True}
which will make sure the connection is valid PRIOR to returning the connection to be used.

Getting gobbledegook from SQL server on mysql turns out its a old codepage.Why is it set up like this? How do I change the defaults?

I'm writing a new project that utilises MySQL , There is no problem with the app I'm working on, but when the app recives the output from my sql server it immediately rejects it as null. When accessing my SQL server on port 3306 I am getting strange garbled messages back as well as the short message 'packets out of order.' In my setup I have, MAMP, Docker, Apache server and PHP. I can access each service on its respective port just fine.
1) I have looked into this by running console in the browser which reports the text being incorrectly formatted to something that isn't utf-8
2) I have followed this guide
https://medium.com/#manish_demblani/breaking-out-from-the-mysql-character-set-hell-24c6a306e1e5 and the results that my sql server have churned out are as follows
enter image description here
My question is this. Why is MySQL set up in this strange fashion? Why is it presenting in CP850 /DOS/ Latin? Are there no defaults/config files to change or is it done through windows somewhere
It seems you somehow messed up the client configuration (connection string, [client]-section of your cnf file (on the system that you started the mysql console on), ...). It tells your server to send data in cp850. Not sure why you would get packets out of order, maybe you have an additional underlying problem (very old library maybe?), but I'd start there. It's unclear: did you follow the blog post and then had problems, or was that a solution attempt? In any case, try to focus your attention on the client. Try to undo changes you made. MySQL uses utf8 by default for a long time now. – Solarflare

MySQL Workbench Manage Server Instances

I successfully installed MySQL server (I can connect to it manually through the MySQL shell). When I try to establish a connection through MySQL Workbench, the test connection goes through as well. But when I try to view the server's info or interact with the server, an error message pops up that says, "Current profile has no WMI enabled." I have searched for a solution to this problem, and found a few threads like this one: https://www.quora.com/MySQL-Workbench-How-can-I-solve-the-Current-Profile-Has-no-WMI-enable-error-message. However, I just can't find the 'Manage Server Instances' dialog or button anywhere. I am running workbench version 6.3. If anyone has run into this problem then I would appreciate a workaround.
It's unusual that you get that error again. I haven't heard since years of such a problem. Anyway, the solution is still to configure the connection properly. That "configure server instances" link is very old (from WB 5.x). Instead look for the connection editor (titled: Manage Server Connections). You can open the dialog either via the main menu or the small wrench button on the homescreen:

Due to Zone.js in Angular Universal server rendering stops working. How to fix?

When in my requests for data I return simple JSON without connection to database the server rendering in Angular Universal works fine.
However I have found that requests to MySQL database is not going if I don't have a proper version of Zone.js.
I had the following error:
TypeError: Cannot read property 'on' of undefined
at Protocol._enqueue (/Applications/MAMP/htdocs/Angular2/myproject/node_modules/mysql/lib/protocol/Protocol.js:152:5)
...
Also I payed attention that I had a warning:
angular2-universal#2.1.0-rc.1 requires a peer of zone.js#~0.6.21 but none was installed.
So I installed proper Zone.js:
npm install zone.js#0.6.21
and I started receiving data from MySQL.
BUT! At this point server rendering stops working! I only see:
<!--template bindings={}-->
in HTML-template.
I moved back to return a JSON without connection to MySQL and have found that even at this case server rendering is not working.
So I have played a little with this and have found that if I use command:
npm install zone.js
then server rendering works properly when I return JSON without connection to database, but if I try to connect to MySQL then original error occurs.
So now I have either working server rendering or connection to MySQL without server rendering. Not server rendering and working connection to database.
If anyone knows what should be done I'll appreciate the help. Thank you.
I have found the solution. In my case the issue was resolved by the command:
npm install zone.js#latest
Now I can do the requests to MySQL and also I have a server rendering and can see all the data in my HTML-template.

"MySQL server has gone away" error after few hours of inactivity

I have a Django app running on Apache with wsgi module.
After few hours of inactivity I get that error and I have to restart the Apache.
Any ideas?
Thanks
This error message mean that the database server has closed the connection to you. I guess this is caused because the connection is idle.
I believe you can get this fixed by adjusting the wait_timeout inside the configuration file of your mysql database server. The file is most commonly named "my.cnf".
This, however, is not considered as a good practice. I would like to suggest you to optimize the application you are writing to open the connection to mysql on demand - there's no point to keep it open if you are not actively using it for a long time.
If you need a quick fix, use the mysql_ping() function to check whether the connection is still alive and re-open if necessary.