"Lost Connection to Database" during Rails Migration? - mysql

I am building an app with Ruby/Rails and using a MySQL database.
Recently, I started having the following issue: sometimes, when doing a Rails migration, Rails drops my DB table!
When it drops the table it gives the following error:
"MySQL2:error: Lost connection to MySQL server during query: ALTER TABLE . . ."
My internet connection is good. It has happened twice so far. The first time the migration involved the following methods: remove_column, add_column, add_foreign_key. The second time it contained only remove_column and add_column.
The migrations are not huge files with a maximum of 10 lines.
Why is it doing this? What can I do to fix it?

Related

Error creating new User in MySQL workbench

I am getting an error in my SQL workbench when I create a user in my db.
I was given a schema to upload to my db I imported it successfully with no errors in Data import/restore tab. I have the correct userName and password but any time I try and save a user I get this same error.
I've checked the tables > Columns folder and I see the name column is listed. And I've tried dropping the db / schema and starting from scratch a couple times just incase something went wrong with that part.
I am new to using MySQL and working with DB's and schemas in general. So I'm not sure where to look to solve this error. I could use an idea of where this error could be coming from? And any advice on handling it.

joomla database is not responding

In the joomla 3.7 site, everything was running OK. But last night suddenly it has gone totally down, throwing error msg
"Application Instantiation Error: Could not connect to MySQL"
The last operation performed by me was editing a comment as admin. When clicked "SAVE" after editing, the error appeared. The tables were MYIASM.
The check_database or repair_database option in cpanel also do not respond. In phpMyAdmin, I can view the table list but running any query is halting with error
"Lost connection to MySQL server during query
.
Can not back up the database either from cpanel or phomyadmin or mysqldump.
2006 - MySQL server has gone away
But I have another drupal database in the same host. Tt is serving the site and all the above operation work on it without any problem.
The joomla db was in myIASM format. after all errors, I tried to convert the tables to InnoDB. But the ALTER TABLE query also halted in middle. Some tables are Innodb and some are MYIASM now.
Please help me to solve the problem.
Update:
After some checking, I found that the database is throwing error as
already has more than 'max_user_connections' active connections when
trying to connect
But there is no active connection visible in "show processlist"
In your .cfg or .ini,
log_warnings=2 for logging to your error log, including connection failure details.
To determine how many connections are possible,
SHOW GLOBAL VARIABLES LIKE 'max_connections'
and increase by 10% with
max_connections=(newlimit)
both within [mysqld], shutdown, restart
remember SET GLOBAL general_log=1 will track everything MySQL is trying to do for your analysis when you are having troubles.
Remember to turn OFF general_log before you go to lunch (or anywhere).

PG::UndefinedTable: ERROR: relation 'caves' does not exist

I've ran into a problem in which I'm not sure how to get out of this. Working on creating a rails view, and after populating my view and editing my controller, i've ran into an error that states PG::UndefinedTable: ERROR: relation 'caves' does not exist
Looking into what I did, I realized that I created my model as cafe but when I populated my schema tables, I accidentally created a table called caves instead of cafes.
Here's what I did to try to resolve this.
I first tried creating a migration to just rename the table from caves to cafes -- still ran into the same error
I then tried deleting the schema table all together and creating a new one all together called cafe - still ran into the same error
I then tried dropping my database all together, thinking if I just wiped the whole thing and started over (i just started on this rails project). I ran rake db:reset only to come into a new error telling me ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR: database "cafe_database" is being accessed by other users
By this point, I tried restarted my postgress and ran sudo service postgresql restart....but my machine doesn't recognize service
Does anybody have an idea what I can do to figure this problem out? I'm running out of ideas.
try below steps:
1. rake db:drop
2. rake db:create
3. rake db:migrate

Force to reconnect MySQL in Rails

How to force MySQL reconnect at my will in Rails application? I would like to do this either periodically or on DB exceptions like "MySQL server has gone away".
I found ActiveRecord::Base.remove_connection but as it is written, it should be called for some model, not the whole application.
It's a huge pain to restart the Rails console when I'm running it via Heroku with a bunch of objects in variables and then lose my database connection.
The following is code I would not consider "good" to put in your actual application but it temporarily gets over the oft encountered Mysql2::Error: closed MySQL connection in a console:
ActiveRecord::Base.connection.reconnect!
How about using reconnect = true in your database.yml as described here?

Error in configuring MySql workbench - Failed to connect to MySql at localhost

I am new to MySql workbench and never needed to use a lot of DBs before now.
I had an sql script containing all the DB creation, tables, population etc.
So using MySql workbench, I Reversed Engineering Using a Create Script.
Fine, it worked as I can see my tables.
Now I want perform some select over my data and I first need to create a new connection,
So I tried to Creating a MySQL Connection
but when I test the connection, I get the following error: "Failed to connect to MySql server on 127.0.0.1" (10061).
Question: what to use in the below menu (Connection/RemoteManagement/System Profile) or what else could be my problem?
my problem was that I didnt have a db, so I decided to use wampserver which includes everything and it's very simple to use.