0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ubuntu24 mysql 外部サーバでバックアップmysqldumpコマンドの使い方。

0
Last updated at Posted at 2026-01-27

大分前にもMySQLの外部サーバへのバックアップに関する投稿をしましたが、MySQL8以降はroot権限での外部アクセスが出来ない様で、CREATE USERにて、作成したユーザにバックアップ権限を与えると云う方法で、mysqldumpを使用して、backup.sqlをとる様になります。
mysql -u root -pにて任意のユーザ追加。

mysql -u root -p
CREATE USER '任意の名前'@'%' IDENTIFIED BY '任意のパスワード';
ユーザ追加を表示して確認
mysql> select user, host from mysql.user;
+------------------+----------------+
| user             | host           |
+------------------+----------------+
| 任意の名前         | %              |

GRANT ALL PRIVILEGES ON 任意のDB名.* TO '上記のユーザ'@'%';

mysqldumpコマンドにてバックアップ。

mysqldump -h ***.***.***.*** -u username--password=“pass” --no-tablespaces --single-transaction :****_db> bkup.sql
上記の様にsellに直接IPアドレスは記せず、下記のようにconfigファイルに記述。
/etc/sqlxxx.cnf
[client]
user = username
password = pass
host = xxx.xxx.xxx.xxx

バックアップシェル下記に。

#! /bin/sh
  
mv ******_dbbackup.sql ******_dbbackup2.sql //前回分コピー

mysqldump --defaults-extra-file=/etc/sqlxxx.cnf --no-tablespaces --single-transaction ******_db > ******_dbbackup.sql

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?