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.
Related
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.
XAMPP has changed from InnoDB to MariaDB some time ago. As I need a newer version of PHP and MySQL I need the new version of XAMPP. Now my database dump of the old XAMPP is very big as all past projects are within this DB.
It looked like I had problems with importing the native mysql tables
information_schema
mysql
performance_schema
phpmyadmin
test
Therefore I did the following in the old xampp installation:
First export all database names except the native ones:
SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('mysql','information_schema','performance_schema','phpmyadmin','test');
Second dump all databases except the native ones:
mysqldump -u root > all-dbs.sql --databases db1 db2 .....
In the next step I imported the dump within PHPMyAdmin which seems to work (import still running while writing this).
Now my question is: Do the native tables of mysql contain important data of my old projects or can I safely go on with the new ones?
When i just write "mysql" in bash - it show only 2 databases.
When i write mysql -u root -p and then enter password - 2 more db occur.
Why is it happening?
+ bonus question: i backed up "data" directory from previous mysql installation, which crashed.
How to restore tables from .ibd and .frm files?
mac os 10.9
Why is it happening?
As documented under SHOW DATABASES Syntax:
You see only those databases for which you have some kind of privilege, unless you have the global SHOW DATABASES privilege.
Presumably the account under which you connect to MySQL when no explicit credentials are provided (i.e. as set in the relevant option file) only has permission to see two of your databases.
How to restore tables from .ibd and .frm files?
See Copying Tablespaces to Another Server (Transportable Tablespaces). If the files are in the server's data directory, you can use IMPORT TABLESPACE:
ALTER TABLE tablename IMPORT TABLESPACE
I have just reinstalled WAMPSERVER without backing-up the data folder of MYSQL under WAMPSERVER, with the understanding that uninstalling and re-installing WAMPSERVER would leave the data directory of MYSQL intact as it is. This was a re-installation of the same WAMPSERVER version.
So now I login to MYSQL, can see all databases and tables from previous WAMPSERVER using SHOW DATABASES, and SHOW TABLES IN myDb. But trying SHOW COLUMNS IN myTable or further attempt to access the data in these tables fails, giving the error:
ERROR 1146 (42S02): Table 'myDb.myTable' doesn't exist
and the logfile:
2013-10-08 14:42:23 1072 [Warning] InnoDB: Cannot open table myDB/myTable from the internal data dictionary of InnoDB though the .frm file for the table exists.
try an CREATE if not exists query, see what output this gives.
I imported a MySQL dump file into my MySQL server using following command.
mysql> create database database_name;
mysql> use database_name;
In Linux command prompt,
$ mysql -u user_name -p database_name < /tmp/test1.dmp
But, while viewing the database using phyMyAdmin the newly created database_name does not show table relations. It shows only the tables, but not relations.
Is there any set up required before importing the database in mysql database?
How to extract the relations between tables?
I just went through the exact same problem.
Is there any set up required before importing the database in mysql database?
Not exactly, but it seems LAMP Server installed on Ubuntu or any Linux Distribution uses MyISAM storage engine by default while creating tables. On InnoDB supports Foreign Key relation. [more info]
To change the storage engine afterwards. [Source answer]
You have to add the line default-storage-engine = InnoDB under the [mysqld] section of your mysql config file (my.cnf or my.ini depending on your operation system) and restart the mysqld service. I don't believe you can change this through phpMyAdmin.
On ubuntu, my.cnf is located inside /etc/mysql/.
Or, you can use mysql command
mysql> SET storage_engine=InnoDb;
After this, all the tables and database you create after this, will use InnoDB as their default storage engine, thus eliminating the issue afterwards.
How to extract the relations between tables?
After you change default engine of your database. You also have to change the default engine of your tables, because they haven't been changed yet. Use the syntax below to change the storage engine
ALTER TABLE <table_name> ENGINE = innodb
Using phpMyAdmin
Go to the operations tab after selecting a table
Go to the table options [See below]
You will see an option to change the storage engine of the table
Change the storage engine to InnoDb and hit Go
After this, export the database using phpMyadmin or dump your database using mysqldump. it will show the relations.