I copied a database directory from the datadir (/var/lib/mysql/) of a MySQL instance running on a server to my local machine. Is it possible to put this database directory into my local MySQL datadir and access that database?
What I have done so far is copy the database directory like above, I log in to the MySQL and can see the database, I switch to it and can list all the tables. But when ever I try to query a table I get something like:
select * from users limit 1;
ERROR 1146 (42S02): Table 'users' doesn't exist
Also from mysqldump:
mysqldump: Got error: 1146: Table 'very_first_table' doesn't exist when using LOCK TABLES
Is it possible to do what I am trying to do here?
So I got it to work, bare in mind that my end goal was to get a database dump from the database. The mysql folder was extracted from a older virtual machine snapshot which could not be run at the moment, so I couldn't just log in to it and do a normal dump. Here is what I did:
1) I installed mysql on a fresh vm on my local machine
2) I shut down mysql with service mysql stop
3) I removed the existing /var/lib/mysql folder from the fresh install
4) I replaced it with the /var/lib/mysql folder that was removed from the old snapshot
5) I ran chown -R mysql:mysql /var/lib/mysql
6) I restarted mysql with service mysql start
7) Then I checked if I could log in and query the tables, I could!
So I was able to run the dump after that.
Related
I am fixing a server that uses Bitnami to run a WordPress site. I did not set up the server – it ran out of memory and crashed.
I was able to restart MySQL through the bitnami ctlscript, and I am able to access the MySQL CLI, but I cannot execute any queries that return data INSIDE the tables.
The following commands all work, and generate the expected output:
show databases;
use database 'x';
show tables;
As soon as I try to view table data (SELECT * FROM ...), this error shows up:
2019-01-15T18:25:19.507808Z 233 [ERROR] /opt/bitnami/mysql/bin/mysqld.bin: Can't find file: './bitnami_wordpress/wp_options.frm' (errno: 13 - Permission denied)
What I've tried:
Database file permissions. All data (specifically the
wp_tablename.frm files) is chowned by mysql:mysql
I confirmed this by changing permissions to my server user, restarting and trying to access mysql again, but the commands above, which already worked, broke, so I changed it back.
Reboots of all sorts. Bitnami, server, etc.
Selinux. I am 95% sure it is not running on this server (all commands
that check its status / install info return 'use apt-get to
install this package) or something like that.
Please help! This site is in production!
Issue
When starting a mysql deployment on OpenShift V3 I get the following exception:
mysql.user table is damaged. Please run mysql_upgrade
I cannot run mysql_upgrade as pod isn't ready.
Questions
I have the following questions
How can I fix this, or
How can I backup the data
If the pod won't start, you can mount the volume with your data to another pod and download (oc rsync, interactive tutorial here) what you had mounted in the database pod under /var/lib/mysql/data/. Then, you can try recovering the data from that.
Generally, this could happen if you process an older database dump sql script (created using mysqldump) on a newer MySQL version. In that case, chances are the root user was removed from the table too (if it was not in the old database). If you created such a dump, still have the older dump, and it's "good enough", you should be able to proceed as follows to import the original data again and prevent this situation:
Create a backup copy of the database dump that you have previously created using mysqldump from the older MySQL database version, so that you can always get back to it, if things go south.
Edit the database dump sql file and remove all the content that manipulates the mysql.user table; that is, delete lines under the -- Table structure for table 'user' and -- Dumping data for table 'user' sections and save the modified file. I assume here that you have your user and password specified in environment variables, in the MySQL deployment configuration).
Scale down your database pod to 0 replicas.
Delete your mysql persistent volume claim; this will delete the database that you have hopefully downloaded after mounting the volume to another pod, as mentioned above.
Recreate the PVC, under the same name.
Scale up your MySQL pod to one replica. That will initialize the database and create a user as per the environment variables .
Copy the modified sql dump file created in step 2 (that is, the one not affecting the mysql.user table) to the database pod using oc rsync.
In the MySQL pod, restore the database using the uploaded file, as per this migration guide (step 6).
Grant all privileges to your user on the application database by GRANT ALL PRIVILEGES ON <database> TO '<mysql_user>'#'%' (Replace <database> and <mysql_user> appropriately.)
Exit the MySQL CLI on the pod, and run mysql_upgrade -u root in the shell.
I had to reinstall MySQL some time ago, before doing it I had moved /var/lib/mysql/mydatabase to another directory to be able to restore it after installation of MySQL.
After I installed MySQL I moved back this directory. When I go to mysql console and use
SHOW DATABASES;
it returns list of databases and 'mydatabase' is among the list.
When I switch to using 'mydatabase' and use
SHOW TABLES;
it shows the list of tables, but when I do any SELECT command I get this error:
ERROR 1146 (42S02): Table 'mydatabase.mytable1' doesn't exist
From the very beginning - was it enough to backup only /var/lib/mysql/< DATABASE_NAME > to restore database data or have I missed something? If yes then what I could try to fix this issue with 'table doesn't exist'?
MySQL version is 5.7, OS is Ubuntu 16.04
MySQL 5.7 default storage Engine is InnoDB. This stores the data in ibdata,ib_logfile0, and ib_logfile1. If you haven't backed up these files then you cannot restore the data.
It is suggestible that instead of moving your database files we should use mysqldump utility.
It is better to use innodb-file-per-table which can store InnoDB tables in a .ibd file per tables.
I don't want to install MySQL on my computer, I don't want to change configuration of my OS, I want just start the mysql process writing the db on a local folder given from parameters.
I downloaded the mysql bundle from the mysql web site, and tried to start it using the mysqld command inside the bin folder in this way:
./bin/mysqld -b /Users/me/tools/mysql-5.6.28-osx10.10-x86_64 -h ~/Projects/my-project/db
But I have this error when it executes:
2016-01-25 11:13:24 33251 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
Everyone can read and write in the db folder, what can be the problem?
Solved.
I found this page in the mysql doc http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html.
To create and start a new db is needed to execute mysql_install_db (before Mysql v5.7.6) using the appropriate datadir and basedir.
In MySQL 5.6 the script is located under the scripts folder, not in the bin folder as is wrote in the docs.
My problem is: I'm saved the /var/www/virtual and the /var/lib/mysql directories. And after reinstall OS I set up the MySQL and when restored these two directories i'm got error in mysql server. So MySQL server don't want to start up.
So what way can i restore the mysql database directory?
The MySQL server don't start after I copy the ibdata1 file.