MySQL corrupts after every server restart - mysql

I Have a bit of an odd problem. I am running MySQL and Drupal site from a windows environment (not by choice but it is just how things have worked out) and most of the time the site is fine however every time the server is restarted (from updates or for maintenance) The MySQL Database will corrupt.
When I log in to MySQL Work bench I notice that the server status is stopped and when I try to start it I get the error:
ERROR Fatal error: Can't open and lock privilege tables: Can't find file: 'user' (errno: 2 - No such file or directory)
and then MySQL Server fails to restart.
The only way around this problem is to delete data folder in the ProgramData/MySQL and then replace it with a backup from a fresh install of MySQL then import a backup of my tables and recreate my users.
My Question is what is causing MySQL to corrupt at every sever restart and what can I do to prevent this happening moving forward?

This occurs when mysql can not find or do not have permissions to user.MYD or user.MYI or user.frm in the data directory. When you start mysql, make sure that these files exist in data directory. You can just copy those files when mysql does not start

This worked for me:
Stick with the 32 bit.
Uninstall and make sure you then DELETE the mysql-data folder and all its subfolders before installing, and prefer to use the 32 bit (sometimes 64 bit versions are the problem).
(Source)

Related

Migrating a Mariadb/wordpress site with only .frm files

My server crashed. My /home /www and lib/mysql were on a different hard disk so I have all the data. The original server was Debian 9 with Mariadb and an apache webserver. I planned to move to mysql so I have a debian 10 server with mysql. I also have another debian 9 server with Mariadb so that I can use sqldump to move my databases. All my databases moved over fine, except one that was a wordpress database. That directory only has .frm files in it, there are no .MYD or .MYI files. I tried copying them to /var/lib/mysql of the Deb9 server, changed the permissions and ownership. However, mysql dump gives the following error message
mysqldump: Got error: 1932: "Table 'dbname.tablename' doesn't exist in engine" when using LOCK enter code here
I tried copying them as is to the MYSQL server too, the server did not see the tables. In the MariaDB server command line interface it shows the tables. However when I try to view the contents of any table it says
Error 1932 (42S02): Table 'dbname.tablename' doesn't exist in engine
I get the same error when I try repair table.
Any ideas on how I can get this moved?
I have resolved my issue. Instead of copying only the database folder, I copied the entire /var/lib/mysql folder to the mariadb install. Then I did sqldump on each database and moved them to the mysql server. I'm not sure why the copy of the database folder didn't work but I got all my data back.

How to restore mysql database in XAMPP

I have been using XAMPP on Ubuntu for a while and I had created a DB via phpMyAdmin with a single DB and multiple rows.
After having to restart my PC, I could not restart XAMPP, so I did install it again (ran the installed.sh without installing first)
Installation was successful and web server is working fine with old files retained.
But, I find that I cannot access the table any more, even though I see it listed via phpMyAdmin and gives an error "Table does not exists in the engine".
However, I can see the table.ipd, table.frm and db.opt inside /opt/lampp/var/mysql/
Is there a way to restore the table from the XAMPP stack?

Restore the mySQL database from files - Windows server

I have tried everything I can find now for over 3 days straight to recover a mySQL database on Windows.
What happened?
I have a Windows Server 2012 that crashed which had WordPress on it and the MySQL 5.1 database for WordPress with no backups. Is there no way to recover from this with a database backup even if you have all the files?
What I have tried!
Attempt 1 recovery (try to add the database from the crashed server to the current mySQL instance):
I reinstalled a new MySQL 5.1 on to the new Windows Server 2012
system and I moved just the /data/wordpress953 folder over
“completely” from the crashed system (which was working fine) into
the /data folder of the new MySQL install.
I start up MySQL and login just fine. I see my database. I see all the tables. However, if I go to a table to view it and I get the following error.
1146 = Table ‘Wordpress953.wp_commentmeta’ doesn’t exist
Attempt 2 recovery (try to completely replace the current mySQL instance files from the crashed server on top and overwrite the new instance):
I completely move over the /data folder from the old server replacing it on the new server
I completely move over the /program files/mysql folder over from the old server onto the new server
I completely move over the /program files (x86)/mysql folder over from the old server
I startup mysql and go to phpmyadmin and get the following error when I try and login:
1045 Cannot log in to the MySQL server
I figure I just need to fix the root password so I attempt to change the root password using this process https://www.youtube.com/watch?v=dyc5b3yT2tI but it fails to even start mySQL to change the password.
Please help with an answer of something I haven't tried....
Ok, I got it!!
The procedure is.
Install vanilla mySQL on new server (I had already done that)
Stop mySQL service
Move ONLY the C:\Program Data\data\wordpress953 (the innodb database you want to restore) folder over “intact” “as is”.
And, move ONLY the ibdata1 file and ib_logfiles off of the original C:\Program Data\data\ root to the new mySQL server. Leave the C:\Program Data\data\mysql folder “as is” from the vanilla install
Re-Start mySQL service
It was a bit of a puzzle because it was basically an “incarnation” of what I was doing but you have to only change/do certain things. The C:\Program Data\data\ibdata1 file down one level in the root went with the C:\Program Data\wordpress953 folder but apparently not with \mysql.

Restore InnoDB database

Today when trying to start mysql service, I got this error :
"mysql: job failed to start"
I needed to work with mysql, so I made a backup of my data directory (/var/lib/mysql) and reinstalled the server (mysql-server-5.6), note that I couldn't have used mysqldump because mysql wouldn't start, even with innodb_force_recovery>0
Now mysql starts just fine, but if I put back the old data directory, it shows the error mentioned before. I concluded that the problem comes from corrupted data
Now all I have is this data folder (containing ibdata1, ib_logfile* and such) and I want to restore all the data (not only the structure).
Thank you
"Old" and "new" are the same version 5.6? Try to check privilege of files, folders too.
Good luck.
I hope you tried all innodb_force_recovery values including 6. If MySQL still doesn't start follow instructions in my post https://twindb.com/recover-corrupt-mysql-database/ . There is a web interface to the data recovery toolkit on https://recovery.twindb.com/, you can upload and recover the database there if you are ok uploading the data.

Mysql gives me:"Can't open and lock privilege tables: Table 'host' is read only"

I am facing problem restoring the mysql database. My primary database was mysql5.1 and now I am trying to copy it to mysql5.5. The database was backed by using Xtrabackup.
I am using Ubuntu 12.04.3 LTS on this server, mysql version is : 5.5.32-0ubuntu0.12.04.1-log
I have followed all the steps to restore using Xtrabackup, this created database files, which I have copied to a tmp directory.
I have modified my.cnf to point to this tmp directory. I have changed the tmp directory permissions and changed the ownership of the files to mysql user.
drwxr-xr-x 12 mysql mysql 4096 Sep 10 10:04 base
Now when I start the mysql server I get this error "[ERROR] Fatal error: Can't open and lock privilege tables: Table 'host' is read only"
I have given a try as follows:
Even tried installing mysql5.1 to see if that was the issue.
tried 'chcon mysql_db_t' to change the context but it gives me "can't apply partial context to unlabelled file"
I have used --skip-grant to get into database, but using this I can only access innodb tables only, MyIsam tables throw read-only error
After --skip-grant, I have used upgrade_mysql this throws me error that many tables are read-only.
I have removed apparmor too. and restarted too.
I have restored a different database(5.1 to 5.5) previously on Ubuntu 12.04.2 LTS without any issues.
Can some please point me in right direction, I am not sure whats wrong with permissions.
Thanks in advance.
Answering my own question,
The issue is with AppArmor. I am not sure why MySql is unable to access files even after uninstalling AppArmor.
Reinstalled AppArmor and moved the MySql profile under disabled profiles of AppArmor, even then it did not work.
I copied the database files under /var/lib/mysql/ and MySql stopped throwing errors