简体   繁体   English

MySQL 表在外置硬盘上

[英]MySQL tables on external hard drive

I have a large amount of text data I need to import into MySQL.我有大量文本数据需要导入 MySQL。 I'm doing this on a MacBook and don't have enough space for it so I want to store it in an external hard drive (I'm not really concerned about speed at this point - this is just for testing).我在 MacBook 上执行此操作并且没有足够的空间放置它,所以我想将它存储在外部硬盘驱动器中(此时我并不真正关心速度 - 这只是为了测试)。

What's the best way to do it?最好的方法是什么?

  • Install MySQL on the external hard drive (is this possible on a Mac?)在外部硬盘驱动器上安装 MySQL(这可能在 Mac 上吗?)
  • Install MySQL on the laptop's hard drive and have the tables on the external (how?)在笔记本电脑的硬盘驱动器上安装 MySQL 并将表放在外部(如何?)

One simple hack is to create an symbolic link replacing your current mysql database file location pointing to the external disk.一个简单的技巧是创建一个符号链接,替换指向外部磁盘的当前 mysql 数据库文件位置。 Google symbolic link.谷歌符号链接。

sample usage would be after you shutdown mysql, change the old mysql db folder name to something else, and create the symbolic link using the ln command like below示例用法是在您关闭 mysql 后,将旧的 mysql db 文件夹名称更改为其他名称,然后使用如下所示的 ln 命令创建符号链接

ln -s [EXTERNAL DRIVE PATH] [MYSQL DB FOLDER PATH]

Then move all the previous content of the mysql db folder to the new location.然后将 mysql db 文件夹之前的所有内容移动到新位置。

User user658991 answer is halfway there.用户 user658991 的答案已经完成了一半。

After adding the soft link, you will need to add the following line to /etc/apparmor.d/usr.sbin.mysqld beneath the 2 lines to the old mysql folder.添加软链接后,您需要将以下行添加到旧 mysql 文件夹的 2 行下方的 /etc/apparmor.d/usr.sbin.mysqld 中。

/path/to/mysql/folder/on/the/external/ r
/path/to/mysql/folder/on/the/external/ ** rwk

Without these 2 lines, MySQL fails to start complaining of:没有这两条线,MySQL 无法开始抱怨:

Can't create test file /path/to/mysql/folder/on/the/external/hostname.lower-test
Can't create test file /path/to/mysql/folder/on/the/external/hostname.lower-test
mysqld: Can't change dir to '/path/to/mysql/folder/on/the/external/' (Errcode: 13)

Restart apparmor for the changes to take effect.重新启动 apparmor 以使更改生效。

sudo invoke-rc.d apparmor restart

With this, MySQL starts normally.至此,MySQL正常启动。

Open /etc/mysql/my.cnf and find the value of the datadir .打开/etc/mysql/my.cnf并找到datadir的值。 Alternatively, you can find this out in the mysql monitor with或者,您可以在 mysql 监视器中找到它

mysql>   select @@datadir;

Stop mysql停止 mysql

sudo systemctl stop mysql

Copy the data from there to your external drive将数据从那里复制到您的外部驱动器

sudo rsync -av /var/lib/mysql /mnt/myHDD/somedir/mysql

Modify the location of the datadir in my.cnf .修改my.cnfdatadir的位置。
Start mysql again再次启动 mysql

sudo systemctl start mysql

Verify that everything is still fine and remove the original data dir.验证一切仍然正常并删除原始数据目录。

This page contains a more extensive guide but all the additional issues it warns about were not relevant for me on my raspberry PI. 此页面包含更广泛的指南,但它警告的所有其他问题都与我的树莓派无关。 Ie I skipped them and it worked.即我跳过了它们,它起作用了。

For the second option, a tablespace might do the trick:对于第二个选项,表空间可能会起作用:

http://dev.mysql.com/doc/refman/5.1/en/create-tablespace.html http://dev.mysql.com/doc/refman/5.1/en/create-tablespace.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM