Raspberry PiでMySQLの保存先を変更する方法
3232 ワード
概要
Raspberry PiでMySQLを使用する際にデータベースの保存先を外付けSSDにしたかったが、configのdatadir=
を変更しただけではMySQLが起動しなくなった。
$ systemctl status mysql.service
mysql.service: Failed with result 'exit-code'.
Failed to start MySQL Community Server.
$ journalctl -xe
systemd[1]: mysql.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit mysql.service has entered the 'failed' state with result 'exit-code'.
systemd[1]: Failed to start MySQL Community Server.
-- Subject: A start job for unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit mysql.service has finished with a failure.
そんなエラーログを吐かれてもさっぱりである。
どうやら追加設定が必要な模様。
実行環境
- マシン:Raspberry Pi B+
- OS:Ubuntu Server 20.04.4
- MySQL:Ver 8.0.28-0
外付けSSDのフォーマット・マウント
パーティション作成
$ sudo parted /dev/sda
(parted) mklabel gpt
(parted) mkpart
Partition name? []?
File system type? [ext2]? ext4
Start?0%
End? 100%
Warning: You requested a partition from 0.00B to 128GB (sectors 0..250069679).
The closest location we can manage is 17.4kB to 1048kB (sectors 34..2047).
Is this still acceptable to you?
Yes/No?Yes
(parted)q
フォーマット
$ sudo mkfs.ext4 /dev/sdb1
マウント
$ sudo mkdir /mnt/mysql
$ sudo nano /etc/fstab
~~追記~~
/dev/sda2 /mnt/mysql ext4 nofail 0 0
$ sudo mount -all
$ sudo chown mysql:mysql /mnt/mysql -R
MySQLの設定
$ sudo systemctl stop mysql.service
$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
~~[mysqld]以下 追記、又は編集~~
datadir = /mnt/mysql
AppArmorの設定
$ sudo nano /etc/apparmor.d/tunables/alias
~~追記~~
alias /var/lib/mysql/ -> /mnt/mysql/,
$ sudo systemctl restart apparmor.service
MySQLのデータを移動・再起動
スラッシュの付け方を間違えると、階層が変わるので注意
$ sudo rsync -avuz /var/lib/mysql.bak/ /mnt/mysql
$ sudo systemctl start mysql.service
参考文献
straightweeds.hatenablog.com 様
RaspberryPiにmysqlをインストール
DigitalOcean Community 様
How To Move a MySQL Data Directory to a New Location on Ubuntu 16.04
Author And Source
この問題について(Raspberry PiでMySQLの保存先を変更する方法), 我々は、より多くの情報をここで見つけました https://qiita.com/Aiagate/items/4d0f55a4c288ac8e6fa1著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .