Unknown behaviour of mysql - mysql

I have a server in my company with mysql installed(on centos machine) in it. It already had data values inserted in it.
This morning when I tried to access my web application(which is connected by mysql) it gives me a database error.
Then I restarted mysql, I checked my database one table is automatically deleted and only 10 rows are inserted with all column value 1. In other table only one column is changed with same value on all row of that column.
I tried to run insert query but it shows timeout.And also phpmyadmin is slow.
I can guess that mysql is slow because mysql memory is full but why it deleted the row from one table and changed only one column of other table??
And is it possible to retreive my old database?
Any help would be apreciated.

Related

Incorrect datetime value in MySQL table

I have just created a new MySQL in an AWS Ubuntu instance.
Then I have copied a table from another MySQL server to the new created database.
This is the structure from some fields from one of the tables:
My issue is that every time I try to enter a new record on the table, there is an error at field fecha_recepcion_disp:
I have checked if the original table from where I have copied the table has the same issue, but no, I am able to enter a new record without issues.
What should I check in the new database or table in order to avoid the issue?
EDIT:
The only difference between both servers is that the first one is located in the USA and the second one is located in France.
Issue solved:
The new server had value NO_ZERO_DATE in sql mode variable.
You're surely using different versions. MySQL 5.7+ stopped supporting zero values in the datetime field.
You can either use as default the current timestamp, or put null.

Mysql retrieve data from back up sql

We back up our mysql database every day around 2.00am.
yesterday, we did an accidental update to a column and that's affected the entire database instead of just one record.
Question :
Is it possible to get a column value from backup and use that to update the live database ?
One way would be to restore the backup to a separate database, query the column in question including the record's primary key.
Then transform the result of that's query into an update statement that you can execute on the live database.
I would advise to try this on a test environment first.

How to repair a specific table in prod database

I have a production database in which I have multiple tables. There is one table in which I store the server responses for the API calls which I receive.
Now that particular table is not working properly. I mean, the data is getting added into that table.
When I click on info button of the table, am getting the details which include number of rows and all. I can see that it's increasing. But the problem is that, whenever I try to execute any query on that table, my MySql workbench crashes.
I tried repair table indoor.ServerResponse; but again this query also doesn't work. It keeps on running and somewhere down the line, it freezes.
I just have few thousand rows in that table.
Now my question is :
1) How do I repair the table ? Did I lose it all?
2) How do I make sure that this doesn't happen in future? As this is the prod database.
3) I am also not able to Alter other tables in the database. But the queries run fine. Why is it so?
P.S. Am using MySql workbench.

how to remove null rows from column in mysql in order to move data to another db

I know there's information on this already but in my particular case the available resources I can find on it aren't working.
I'm trying to copy the data from a table in one database over to another table (also pre-existing) in another database. The table I'm trying to copy from contains null rows at the beginning which are preventing me from copying the data over because the second table will not allow null rows. I've tried deleting them, excluding them, including only the relevant rows, etc. Most of the stuff I've tried won't work with my particular version of mysql (syntax error). The specific error I'm getting when I try to move the data between databases is ERROR 1136.
mysql version: 5.5.41-0ubuntu0.14.04.1

java and mysql load data infile misunderstanding

Thanks for viewing this. I need a little bit of help for this project that I am working on with MySql.
For part of the project I need to load a few things into a MySql database which I have up and running.
The info that I need, for each column in the table Documentation, is stored into text files on my hard drive.
For example, one column in the documentation table is "ports" so I have a ports.txt file on my computer with a bunch of port numbers and so on.
I tried to run this mysql script through phpMyAdmin which was
LOAD DATA INFILE 'C:\\ports.txt" INTO TABLE `Documentation`(`ports`).
It ran successfully so I went to do the other load data i needed which was
LOAD DATA INFILE 'C:\\vlan.txt' INTO TABLE `Documentation` (`vlans`)
This also completed successfully, but it added all the rows to the vlan column AFTER the last entry to the port column.
Why did this happen? Is there anything I can do to fix this? Thanks
Why did this happen?
LOAD DATA inserts new rows into the specified table; it doesn't update existing rows.
Is there anything I can do to fix this?
It's important to understand that MySQL doesn't guarantee that tables will be kept in any particular order. So, after your first LOAD, the order in which the data were inserted may be lost & forgotten - therefore, one would typically relate such data prior to importing it (e.g. as columns of the same record within a single CSV file).
You could LOAD your data into temporary tables that each have an AUTO_INCREMENT column and hope that such auto-incremented identifiers remain aligned between the two tables (MySQL makes absolutely no guarantee of this, but in your case you should find that each record is numbered sequentially from 1); once there, you could perform a query along the following lines:
INSERT INTO Documentation SELECT port, vlan FROM t_Ports JOIN t_Vlan USING (id);