How can I reinstall mysql while restoring DBs without mysqldump? - mysql

I'm running MySQL v5.7.25 on Ubuntu 16.04.5. Recently I noticed MySQL was not responding to any connects or service restart. I want to just purge the server and reinstall it but I have databases I want to retain and I can't use mysqldump to save them as sql files because I can't connect to mysql.
Is ther a way to do this, restore the files in /var/lib/mysql after a purge / reinstall. I've all ready archived the contents of /var/lib/msysql in a tarball, I just want to know if it's just a simple matter of copying the backedup files into the /var/lib/mysql directory before I pull the trigger.

don't use purge it removes everything. instead use remove
/var/lib/mysql folder stays untouched when you remove by using apt-get remove. D

Related

How to reset mysql to factory settings?

So I dropped all the users in mysql.user and restarted the mysql database. Now I can't seem to get into the mysql again or how to reset it as if it was a clean install. I tried uninstalling it with brew uninstall mariadb and then reinstalling it with brew install mariadb, but that didn't fix it. The only resources I can find is about how to restore a user from inside mysql (which I am struggling to get into) or how to delete mysql completely by deleting files in certain directories (which don't exist in the first place).
There are two methods:
method 1:
1.Uninstall the mysql database, delete the data files in the /data directory, and then reinstall
Method 2:
1.Stop the mysql service (systemctl stop mysqld)
2.Delete the files in the /data directory (rm -fr /data/*)
3.Initialize mysql (mysqld --defaults-file=/mysql/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data/)
PS1: The path may be different from yours, you need to change it according to your own data directory
I did end up finding a solution to my problem. I didn't end up getting it from one source, but more cobbled a bunch of different stuff together until I figured out that this worked.
Stop the server: `brew services stop mariadb
Start it with this command: mysql --skip-grant-tables
Run this command to fix the table with no users: mysql_upgrade --force
Force kill mysql: ps -ef | grep mysql followed by kill -9 <pid>
Start up the server again: brew services start mariadb
I did first try mysql_install_db instead of mysql_upgrade --force as some site suggested, but that didn't work since mysql.user table still existed. It was just empty.

Recreate a `mysql.user` table in mysql

I found my mysql.user table is messed up and use drop table if exists mysql.user to drop it, how can I create this special table manually and add my new account to it.
NB I have never tried this so I have no idea if it will work at all. YOU HAVE BEEN WARNED!!
Before you do anything, shut down the MySQL service and take a backup of the data folder (copy it elsewhere).
Next, either try creating a new data directory and run mysql_install_db (from the MySQL install directory, scripts/mysql_install_db --datadir=<new data directory>), or use a virtual machine and do the same. Whatever you do, do NOT install into the original folder. Use the same version of MySQL to do this
Whichever method you use, take the resultant files from <mysql data folder>/data (they should be called user.MYD, user MYI and user.frm) and copy them into your broken folder. Ensure that user rights are the same as the rest of the folder (owner and group should be read/write).
Restart your MySQL service and see if you can get into the system (no login information will be required, but you will have to log in to MySQL as root. If you can, recreate the relevant users for application access. If not, you still have a backup of the data folder.
In the event that it doesn't work, and assuming that you have recent backups, re-create the data folder completely using mysql_install_db (ensuring that you still have the copy of the folder you took before you started out), create the users, then restore your individual databases one by one from your last good backup. Do not restore the mysql database and tables - they will be built as you restore the other databases.
Try all this out on a virtual machine first - it'll help you find any problems along the way
Good luck
Thanks to #DaveyBoy 's answer. I operated like below on ubuntu 16.04, mysql 5.7.20, and got mysql.user table back:
sudo mysqld --initialize --datadir=~/data_tmp
sudo cp ~/data_tmp/mysql/user.frm /var/lib/mysql/mysql
sudo cp ~/data_tmp/mysql/user.MYD /var/lib/mysql/mysql
sudo cp ~/data_tmp/mysql/user.MYI /var/lib/mysql/mysql
sudo chown mysql:mysql /var/lib/mysql/mysql/user.frm
sudo chown mysql:mysql /var/lib/mysql/mysql/user.MYD
sudo chown mysql:mysql /var/lib/mysql/mysql/user.MYI
In mysql cli select * from mysql.user, table mysql.user should show up now.

must re-install WAMP, but want to save my MySQL databases

After installing a newer version of WAMP both WAMP-Installations won't start anymore. I can't figure out why and don't want to waste more time with it as I have to work on a project.
I would like to uninstall WAMP and reinstall again. How can I save all MySQL-Databases? PHPMyAdmin won't start. I see the database data seems to be in folder C:\wamp\bin\mysql\mysql5.6.17\data
Will it work if I just copy that folder, uninstall, reinstall WAMP and copy all data back from that folder?
Of course I would also copy all data from C:\wamp\www before uninstalling WAMP.
Any help is appreciated.
Milan
Take backup of /var/lib/mysql/<your database>
Reinstall WAMP
Restore <your database> back to /var/lib/mysql
Change ownership & group to mysql by chown -R mysql:mysql /var/lib/mysql/
Start MySQL

Mysql backup from a mounted root drive

I had a problem with my hdd. There is a new system running in place and I found that I can mount and access the / of my old hdd (It had a Debian Linux distribution). However I forgot to backup some important data in the DB tables and I was wondering if there was anyway to execute a mysql server command from the mysql server installation in the mounted drive?
If your hdd contains complete OS, you can simply mount it and chroot to it. In chrooted environment start your mysql server and take data-backup with mysqldump command.
Or you can simply install mysql-server on your new system, change data directory option in /etc/my.cnf to the mounted partition, backup the data with mysqldump command. You can then revert the my.cnf change back.

Mysql wont start after changing temp dir on ubuntu 12.04

I run ubuntu 12.04.
I am trying to move the temp dir for files as /tmp has filled up, somehow I only set it to 1meg, which is obviously not enough for a large mysql database.
What I need to do is move it on, so I looked online for a solution to this and I found an article which seems to make sense.
In the my.conf file at /etc/mysql/my.conf I changed the tmpdir directive to /mysqltmp. I made the directory with root login, then chmod 777 that dir. I reboot and the mysql server wont start. (it was starting just previously).
The error log says..
/usr/sbin/mysqld: Can't create/write to file '/mysqltmp/ibqADloJ'
It's a permissions error, however the directory has full permissions so why is this a problem?
Probably apparmor is getting in your way. Have a look at /etc/apparmor.d/usr.sbin.mysqld and make your new temp-folder writable by the mysqld process (or configure mysqld to write its temporary data to a directory it has write permissions for)