问题
I'm using MySQL Workbench and I've built a very large (17 GB) database. MySQL puts the data in a single file called ibdata1 in the C:\ProgramData\MySQL\MySQL Server 5.5\data directory. I'm out of space on my C drive and I would like to move it to my external drive. Is it possible to move that ibdata1 file and then tell MySQL to point to another location to find it? Also, if I want to back up that data, can I just copy the ibdata1 file and save it. And then if my computer were stolen or something, could I somehow recover that data from that file?
回答1:
You can copy/backup the entire C:\ProgramData\MySQL\MySQL Server 5.5\data
to another drive, update the datadir
option in my.cnf
or my.ini
to point to the new location, and restart MySQL.
回答2:
Yes you can change the data directory of your Mysql server.
Stop MySQL server from windows services.
Copy the existing data directory (default located in C:/Program Files/mysql/data) to New Path or Directory.
edit the MySQL configuration file with the following command:
Open the my.cnf or my.ini this file is located in mysql bin directory.
Look for the entry for datadir, and change the path to the new data directory.
Save and close the file.
Restart MySQL server.
回答3:
You have to backup entire /data/ directory and ibdata1 file and put it in a new /data/ directory.
InnoDB is not aware of the file system maximum file size, so be cautious on file systems where the maximum file size is a small value such as 2GB. To specify a maximum size for an auto-extending data file, use the max attribute following the autoextend attribute. The following configuration permits ibdata1 to grow up to a limit of 500MB:
[mysqld]
innodb_data_file_path=ibdata1:10M:autoextend:max:500M
InnoDB creates tablespace files in the MySQL data directory by default. To specify a location explicitly, use the innodb_data_home_dir option. For example, to use two files named ibdata1 and ibdata2 but create them in the /ibdata directory, configure InnoDB like this:
[mysqld]
innodb_data_home_dir = /ibdata
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend
InnoDB does not create directories, so make sure that the /ibdata directory exists before you start the server. This is also true of any log file directories that you configure. Use the Unix or DOS mkdir command to create any necessary directories.
Make sure that the MySQL server has the proper access rights to create files in the data directory. More generally, the server must have access rights in any directory where it needs to create data files or log files.
- The ibdata1 file can´t actually be shrunk unless you delete all databases, remove the files and reload a dump.
But you can configure MySQL so that each table, including its indexes, is stored as a separate file. In that way ibdata1 will not grow as large. According to Bill Karwin's comment this is enabled by default as of version 5.6 of MySQL.
It was a while ago I did this. However, to setup your server to use separate files for each table you need to change my.cnf in order to enable this:
[mysqld]
innodb_file_per_table
来源:https://stackoverflow.com/questions/21273621/moving-and-backing-up-a-large-mysql-database