Flask Internal Web App Dies after a while running on python - mysql

I have a web app meant for internal use only.
I wrote this app in Python 2.7 using Flask and flask-mysql. This app returns data from our MySQL database and returns some fields in a table in HTML. (It is very simple)
Now I am not a programmer and dont know too much on debugging, but I have this problem that the app runs perfect but left for a while it dies.(mostly at night or weekends when I guess it is not used).
Is there any way that I can keep it running, or that when it dies, it should restart.
I will paste my code if needed.
Arnoux

MySQL invalidates stale connections after 8 hours. Try adding a pool_recycle=3600 to your engine configuration. Also, make sure you are properly managing your session. See this previous thread about the MySql has gone away error.
Does this thread-local Flask-SQLAchemy session cause a "MySQL server has gone away" error?

Related

Proper way to backup and restore django project

I have been using Oracle's virtual box to setup an Ubuntu 18.04LTS OS to run my django application. The application is using MySQL as a database. The problem happened a few days ago, all my files suddenly became read-only, which is an indication of hard disk problems as seen in this post.
I have since prepared another server to run the application, however I would like to know the proper procedures in migrating data to ensure that I don't loose any of my files. Could someone point me in the correct direction? Thank you.

Linked server infinite load/wait after server name change

I have been stumped on this for this whole day now. I use MS SQL Server 2008. I have alinked server pointing to a DB2 database using an ODBC connection that has been running fine for years. Today I decided to change the name of the server and now whenever I run an openquery, run a job that connects to this linked server or when I try to see the tables of this linked server the query/job will run permanently and the tables forever say [Expanding...] but they never actually show. When I try to cancel a query that is stuck, it will never finish canceling. The only way I have found to actually stop queries is to log my account out and end my session forcefully (MS SQL server will tell me it cannot shut down but I can log my Windows account out get past it).
We already tried to recreate this exact linked server by scripting it and using a different linked server name but this gave the same result. I also tried recreating this linked server on another actual server and that worked fine. The server where the linked server is "stuck" on, works perfectly fine as long as I don't try to connect/communicate to these broken linked servers.
My question is basically, what in the world happened when I just changed the name of this server and does anyone have any suggestions on resolving this? I have pondered about a complete server restart, but since this concerns a production server this would be my absolute last resort. I however see no other options right now.
Solution was to do a complete server restart and to back up to an earlier date. We have done the exact same thing after that and everything worked fine, so it seemed like it was a one time critical anomaly.

How to diagnose (and repair) persistent mysql errors from a drupal 7 site on an ubuntu 16 server?

I'm deploying a Drupal 7x site to a Digital Ocean Ubuntu 16.04 server for testing and demo purposes. I'm switched the server php versions from php7 to PHP 5.6, but otherwise using the default versions of Mysql and Apache2. I had no problem installing the site and the site functions; however, I frequently have database related errors, specifically, the following one:
PDOException: SQLSTATE[HY000] [2002] Connection refused in lock_may_be_available() (line 167 of /var/www/html/phisigmarho.org/includes/lock.inc).
I typically get that error, but I also get "the website experienced an error" errors or "mysql server has gone away" when I to do anything database or process intensive (updating modules through the UI, etc). I'm relatively new server administration, so I'm not sure what could be wrong or which logs I should be looking at for clues to what's wrong. For the moment, restarting MySQL from the terminal is letting me move forward with setting up the site, but I can't let anyone use the site the way that it is now.
So, how do I figure out why MySQL keeps going away? I'm perplexed, because the server is very similarly configured to my dev machine (ubunutu 16 desktop running php5.6) and I don't have anything remotely similar going on. Where do I look for meaningful logs that will help me diagnose of fix this. So, ideas?
Here are a few things I would try in this scenario.
Install Drush (if not already).
Then see what you get for the following commands:
drush status - check the site configuration looks correct including the DB connection
drush sqlc - this will log you into the MySQL command line using the connection details specified in settings.php. It's worth making sure this connection opens successfully
drush cc all - Clearing your site's caches is always a good idea when migrating to a new environment.
If still not working, I would truncate all the cache_* tables in the Drupal database. I have seen errors similar to above and the normal cache clear wasn't enough to resolve it.
Make sure Drupal Watchdog is enabled. drush en dblog. You can then view watchdog log entries using Drush e.g. drush ws
Check PHP logs. You may need to contact Digital Ocean for location and access to these.

How do I migrate a SQLAnywhere 9 db running in a remote server into a mysql server on my machine?

I am working at a company that has some CRM software running in a remote Windows XP server that uses a SQLAnywhere 9 db to store its data; I have access to this remote server with an administrator account.
I would like to extract the db into a .sql file so that I can run the db locally on my machine without affecting the running db in the server (since it is key for the company's day to day operation).
The reason I need this is that we are going to test some BI Software and we need data from this database to test it, but we don't know the structure of the database since the developers of the CRM software didn't give us any documentation on it. So we need to have the database locally so that, without affecting the running CRM, we can:
understand the structure by looking at the DDL
make queries to it to get sample data
I researched a bit, and the most common solution to my problem was to use dbunload on the remote server to unload the db into a reload.sql file that contained what I needed. But most tutorials on the subject mention that I have to stop the db first (which would be catastrophic). If this is the only option, then I guess I am willing to do it on the weekend when the CRM is not used, but I wanted to know if there was another solution first.
If there is no other solution, can you point me to where I can find the proper and safer way to do this?
I have researched a lot, but prior to this day I have never even heard of SQLAnywhere, so I really need all the help I can get. My main concern is doing something that impacts negatively the CRM software.
Thank you.
You can run dbunload across the network, you just have to tell it to do an "external" unload. The default is to do an internal unload which would only work from the machine where the database server is running.
I don't have SQL Anywhere 9 documentation right now to look up the exact switch, but dbunload -? should show you all the possible switches.
Edit:
-an will create a new database and load the data and schema from another data
-xi switch will do external unload and internal reload.
-c parameters to connect to your remote database

Can I run my own instance of MySQL?

I'm trying to migrate a web site to friend's server. The site uses MySQL, but he didn't previously have it set up. He's installed the package now and suggested that I could run my own instance of it. I'm at a loss for how to do so. Is it even possible? If so, how?
Some relevant information:
The OS in use is CentOS 5.9
Using MySQL 5.0.95
I only need the DB to be read locally via PHP when serving my site.
I have no root privileges on this system (although a full shell), but am close friends with the owner/administrator if that's necessary.
To clarify:
It's the daemon that I want to run my own instance of. So I guess what I want to know is if it's possible to have multiple users on the system running their own instances of mysqld containing different databases.
All I need this for is serving a web page. If I have to break down and switch to a pseudo-database using CSV files I will, but I'd much rather stick to MySQL if I can.
If MYSQL is setup on that machine yes you can run your own instance of it.
You can have it set up and your site given its on Database within that MYSQL instance and that specific MYSQL account can be used to access the tables etc. involved with your website.
Now if he is only putting MYSQL on the machine then having you set everything up you will just need an account for MYSQL and from ther eyou can get in and just create all the needed items that will allow your site to fully function.
EDIT
In response to your comment. You can you just can't clog the same port or have configurations that conflict each other. As long as it won't be to much of a performance hit and you configure a different user to start each instance you should be able to do Something like this.