# Use an import script that requires MySQL

**URL:** https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349
**Category:** Sysadmins
**Tags:** how-to
**Created:** [5월 25, 2017, 11:06오전 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349 "2017-05-25T11:06:53Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![moebis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moebis/32/555233_2.png) [@moebis](https://meta.discourse.org/u/moebis)
#### Post date: [5월 19, 2018, 12:40오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/24 "2018-05-19T12:40:47Z")

</div>

With the latest update ver 2.0.0 beta10 I’m now getting more errors with the bbpress import script (still can’t figure out why images are not being pulled over, but instead referring to their old URLs). Error after the importing topics and posts:

```
importing private messages...
      120 / 120 (100.0%) [156526 items/min] /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:131:in `_query': Table 'db.wp_bp_messages_messages' doesn't exist (Mysql2::Error)
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:131:in `block in query'
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:130:in `handle_interrupt'
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/mysql2-0.5.1/lib/mysql2/client.rb:130:in `query'
	from /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-mini-profiler-1.0.0/lib/patches/db/mysql2.rb:22:in `query'
	from script/import_scripts/bbpress.rb:505:in `bbpress_query'
	from script/import_scripts/bbpress.rb:453:in `block in import_private_messages'
	from /var/www/discourse/script/import_scripts/base.rb:870:in `block in batches'
	from /var/www/discourse/script/import_scripts/base.rb:869:in `loop'
	from /var/www/discourse/script/import_scripts/base.rb:869:in `batches'
	from script/import_scripts/bbpress.rb:452:in `import_private_messages'
	from script/import_scripts/bbpress.rb:32:in `execute'
	from /var/www/discourse/script/import_scripts/base.rb:46:in `perform'
	from script/import_scripts/bbpress.rb:510:in `<main>'

```

---

<div class="post-metadata">

### Author: ![sshanky](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sshanky/32/105783_2.png) [@sshanky](https://meta.discourse.org/u/sshanky)
#### Post date: [8월 1, 2018, 3:11오전 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/26 "2018-08-01T03:11:41Z")

</div>

EDIT: After deeper inspection I found that (at least in my setup) the file was called

```plaintext
  - "templates/import/mysql-dep.template.yml"

```

NOTE that the correct spelling is “ **dep** ”, not “dev”.

=================

Hello! Thanks for posting this. I tried but got this error:

```plaintext
cat: templates/import/mysql-dev.template.yml: No such file or directory

```

I unfortunately don’t know enough about Docker to proceed…What am I doing wrong? Thank you so much. Here is the full output:

```plaintext
root@forum /var/discourse # ./launcher rebuild import
Ensuring launcher is up to date
Fetching origin
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 16 (delta 12), reused 7 (delta 6), pack-reused 0
Unpacking objects: 100% (16/16), done.
From https://github.com/discourse/discourse_docker
   2ad56e6..d032356 master -> origin/master
Updating Launcher
Updating 2ad56e6..d032356
Fast-forward
 discourse-setup | 2 +-
 image/base/Dockerfile | 5 +++--
 launcher | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)
Ensuring launcher is up to date
Fetching origin
Launcher is up-to-date
cat: templates/import/mysql-dev.template.yml: No such file or directory
cd /pups && git pull && /pups/bin/pups --stdin
/usr/bin/docker: invalid reference format: repository name must be lowercase.
See '/usr/bin/docker run --help'.
cat: cids/import_bootstrap.cid: No such file or directory
"docker rm" requires at least 1 argument.
See 'docker rm --help'.

Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers
rm: cannot remove 'cids/import_bootstrap.cid': No such file or directory
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one
root@forum /var/discourse #support

```

---

<div class="post-metadata">

### Author: ![Caliph](https://avatars.discourse-cdn.com/v4/letter/c/b9e5f3/32.png) [@Caliph](https://meta.discourse.org/u/Caliph)
#### Post date: [9월 21, 2018, 10:41오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/27 "2018-09-21T22:41:16Z")

</div>

did you get it resolved? Im too having this error

---

<div class="post-metadata">

### Author: ![moebis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moebis/32/555233_2.png) [@moebis](https://meta.discourse.org/u/moebis)
#### Post date: [9월 22, 2018, 7:43오전 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/28 "2018-09-22T07:43:38Z")

</div>

No. we just manually re-uploaded all of the images.

---

<div class="post-metadata">

### Author: ![Caliph](https://avatars.discourse-cdn.com/v4/letter/c/b9e5f3/32.png) [@Caliph](https://meta.discourse.org/u/Caliph)
#### Post date: [9월 23, 2018, 5:31오전 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/29 "2018-09-23T05:31:12Z")

</div>

So I found out the reason for the issue we were having. The import script is breaking when it is trying to get wp\_bb\_message\_message table, that’s happening because you would not have BuddyPress private messages module (which create these table) installed in your WordPress.

I did manage to pass that error by removing the code in bbpress.rb from line 414 to 502  
This

```
 def import_private_messages
puts "", "importing private messages..."
last_post_id = -1
total_posts = bbpress_query("SELECT COUNT(*) count FROM #{BB_PRESS_PREFIX}bp_messages_messages").first["count"]

threads = {}

total_count = bbpress_query("SELECT COUNT(*) count FROM #{BB_PRESS_PREFIX}bp_messages_recipients").first["count"]
current_count = 0

batches(BATCH_SIZE) do |offset|
  rows = bbpress_query(<<-SQL
    SELECT thread_id, user_id
      FROM #{BB_PRESS_PREFIX}bp_messages_recipients
  ORDER BY id
     LIMIT #{BATCH_SIZE}
    OFFSET #{offset}
  SQL
  ).to_a

  break if rows.empty?

  rows.each do |row|
    current_count += 1
    print_status(current_count, total_count, get_start_time('private_messages'))

    threads[row['thread_id']] ||= {
      target_user_ids: [],
      imported_topic_id: nil
    }
    user_id = user_id_from_imported_user_id(row['user_id'])
    if user_id && !threads[row['thread_id']][:target_user_ids].include?(user_id)
      threads[row['thread_id']][:target_user_ids] << user_id
    end
  end
end

batches(BATCH_SIZE) do |offset|
  posts = bbpress_query(<<-SQL
    SELECT id,
           thread_id,
           date_sent,
           sender_id,
           subject,
           message
      FROM wp_bp_messages_messages
     WHERE id > #{last_post_id}
  ORDER BY thread_id, date_sent
     LIMIT #{BATCH_SIZE}
  SQL
  ).to_a

  break if posts.empty?

  last_post_id = posts[-1]["id"].to_i

  create_posts(posts, total: total_posts, offset: offset) do |post|
    if tcf = TopicCustomField.where(name: 'bb_thread_id', value: post['thread_id']).first
      {
        id: "pm#{post['id']}",
        topic_id: threads[post['thread_id']][:imported_topic_id],
        user_id: user_id_from_imported_user_id(post['sender_id']) || find_user_by_import_id(post['sender_id'])&.id || -1,
        raw: post['message'],
        created_at: post['date_sent'],
      }
    else
      # First post of the thread
      {
        id: "pm#{post['id']}",
        archetype: Archetype.private_message,
        user_id: user_id_from_imported_user_id(post['sender_id']) || find_user_by_import_id(post['sender_id'])&.id || -1,
        title: post['subject'],
        raw: post['message'],
        created_at: post['date_sent'],
        target_usernames: User.where(id: threads[post['thread_id']][:target_user_ids]).pluck(:username),
        post_create_action: proc do |new_post|
          if topic = new_post.topic
            threads[post['thread_id']][:imported_topic_id] = topic.id
            TopicCustomField.create(topic_id: topic.id, name: 'bb_thread_id', value: post['thread_id'])
          else
            puts "Error in post_create_action! Can't find topic!"
          end
        end
      }
    end
  end
end
end

```

You can also get past it by simply installing buddypress and enabling its private message module.

---

<div class="post-metadata">

### Author: ![Samuel\_Polymorphose](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samuel_polymorphose/32/217922_2.png) [@Samuel\_Polymorphose](https://meta.discourse.org/u/Samuel_Polymorphose)
#### Post date: [5월 21, 2019, 2:51오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/31 "2019-05-21T14:51:07Z")

</div>

Thanks for your helpful tutorial , worked fine for me !

Cheers

Sam

---

<div class="post-metadata">

### Author: ![pitp2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pitp2/32/157922_2.png) [@pitp2](https://meta.discourse.org/u/pitp2)
#### Post date: [10월 5, 2019, 5:04오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/32 "2019-10-05T17:04:18Z")

</div>

안녕하세요,  
이 사용법에 감사드립니다. 🙂  
첨부 파일도 함께 가져오나요?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [10월 5, 2019, 6:33오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/33 "2019-10-05T18:33:35Z")

</div>

그렇게 보입니다. 첨부 파일 디렉터리에 대한 설정이 있습니다.

---

<div class="post-metadata">

### Author: ![kenaddams](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kenaddams](https://meta.discourse.org/u/kenaddams)
#### Post date: [11월 23, 2019, 9:30오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/34 "2019-11-23T21:30:32Z")

</div>

> [@lead4good](#):
>
> /backup/yourbackup.sql

안녕하세요,  
죄송하지만 yourbackup.sql 파일을 어떻게 생성하시나요? 이 파일에는 어떤 내용이 포함되어야 하나요? bbpress 데이터베이스의 내보내기(export) 파일인가요?

감사합니다  
++ .

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [11월 24, 2019, 4:29오전 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/35 "2019-11-24T04:29:38Z")

</div>

> [@kenaddams](#):
>
> ? 이 파일에는 무엇이 포함되어야 하나요? bbpress 데이터베이스의 내보내기인가요??

맞습니다. 이를 얻는 방법은 어떤 도구를 가지고 있고 무엇을 사용할 수 있는지에 따라 달라집니다.

---

<div class="post-metadata">

### Author: ![kenaddams](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kenaddams](https://meta.discourse.org/u/kenaddams)
#### Post date: [11월 24, 2019, 8:36오전 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/36 "2019-11-24T08:36:34Z")

</div>

bbpress 설치 과정은 꽤 표준적입니다. WordPress 데이터베이스와 wp\_posts 내부의 모든 게시글이 해당되죠. 따라서 제가 해야 할 일은 WordPress 게시글 데이터베이스를 덤프하는 것뿐인가요?  
다른 설명서를 찾지 못해 죄송하지만 여쭤봅니다.

감사합니다

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [11월 24, 2019, 1:29오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/37 "2019-11-24T13:29:57Z")

</div>

전체 WordPress 데이터베이스 덤프를 가져오거나, 코드를 읽어서 실제로 어떤 테이블이 사용되는지 확인할 수 있습니다. 전체 데이터베이스를 덤프하는 것이 더 쉽습니다.

이를 mysqldump, cPanel, phpMyAdmin 또는 다른 도구를 사용하여 수행할지에 대해서는 권장 사항을 제시하기가 어렵습니다.

---

<div class="post-metadata">

### Author: ![kenaddams](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kenaddams](https://meta.discourse.org/u/kenaddams)
#### Post date: [11월 24, 2019, 5:27오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/38 "2019-11-24T17:27:48Z")

</div>

동작합니다 (조금 수정한 후) 🙂 🙂 감사합니다 😉  
 ![succeed](https://global.discourse-cdn.com/meta/original/3X/d/5/d5bb41eee3484d7ec5c2f95d153db1741c1c6de2.png)

---

<div class="post-metadata">

### Author: ![Rs40x](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Rs40x](https://meta.discourse.org/u/Rs40x)
#### Post date: [4월 4, 2020, 1:26오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/40 "2020-04-04T13:26:06Z")

</div>

가져오기(import)를 실행할 때 MySQL DB에 연결 오류가 발생합니다. SQL DB는 로컬호스트(localhost)에 있습니다. 이 오류를 어떻게 해결할 수 있을까요?

/var/www/discourse# su discourse -c “bundle exec ruby script/import\_scripts/bbpress.rb”

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect’: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) (Mysql2::Error::ConnectionError)

감사합니다.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [4월 4, 2020, 3:31오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/41 "2020-04-04T15:31:06Z")

</div>

MySQL 서버가 컨테이너가 아니라 서버에서 실행 중이라면, 호스트 IP 주소를 사용하도록 해보세요.

---

<div class="post-metadata">

### Author: ![Rs40x](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Rs40x](https://meta.discourse.org/u/Rs40x)
#### Post date: [4월 4, 2020, 6:41오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/42 "2020-04-04T18:41:12Z")

</div>

MySQL은 Discourse가 실행 중인 컨테이너에서 실행되고 있습니다. Discourse 컨테이너의 가져오기 스크립트가 MySQL 컨테이너에 연결할 수 없는 것으로 보입니다. 다른 방법으로 시도해 볼 수 있는 것이 있을까요?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [4월 4, 2020, 7:17오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/43 "2020-04-04T19:17:36Z")

</div>

> [@Rs40x](#):
>
> MySQL은 discourse와 같은 컨테이너에서 실행되고 있습니다

정말 그렇습니까? 컨테이너 내부에서 mysql 커맨드 라인 도구를 통해 해당 MySQL에 연결할 수 있습니까?

---

<div class="post-metadata">

### Author: ![Rs40x](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Rs40x](https://meta.discourse.org/u/Rs40x)
#### Post date: [4월 4, 2020, 7:19오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/44 "2020-04-04T19:19:25Z")

</div>

해당 문제를 해결했습니다. 처음에는 localhost를 사용하다가, MySQL의 IP 주소는 아래 명령어로 확인해야 한다는 것을 깨달았습니다.

```plaintext
docker inspect mysql | grep IPAddress.

```

다음은 임포트 스크립트 관련 문제입니다.

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect’: Plugin caching\_sha2\_password could not be loaded: /usr/lib/x86\_64-linux-gnu/mariadb19/plugin/caching\_sha2\_password.so: cannot open shared object file: No such file or directory (Mysql2::Error::ConnectionError)

ALTER 명령어를 사용하여 비밀번호를 변경했습니다.

---

<div class="post-metadata">

### Author: ![Rs40x](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Rs40x](https://meta.discourse.org/u/Rs40x)
#### Post date: [4월 4, 2020, 7:33오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/45 "2020-04-04T19:33:19Z")

</div>

위 문제를 해결하기 위해 다음 명령을 다시 실행했습니다.

```plaintext
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY 'newpassword';

```

---

<div class="post-metadata">

### Author: ![thwright](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@thwright](https://meta.discourse.org/u/thwright)
#### Post date: [3월 13, 2021, 4:24오후 UTC](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349/46 "2021-03-13T16:24:00Z")

</div>

위에서 게시된 여러 수정 방법을 시도해 보았지만, 임포터 실행 시 실제로 게시물이 가져와지지 않고 있습니다. 새 데이터베이스에 성공적으로 연결되었는데도 게시물이 가져와지지 않는 이유는 무엇일까요? 어떤 생각이 있으신가요?

bbPress가 아닌 WordPress(5.7) 사이트에서 몇백 개의 게시물을 이미 운영 중인 Discourse 사이트(2.7.0-beta5, 몇백 개의 게시물 보유)로 가져오려는 중입니다.

가져온 DB가 존재하는 것으로 보입니다:

```plaintext
mysql> show tables;
…
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
…

```

> **임포터 실행 시 출력:**
>
> ```plaintext
> /var/www/discourse# su discourse -c "bundle exec ruby script/import_scripts/bbpress.rb"
> Loading existing groups...
> Loading existing users...
> Loading existing categories...
> Loading existing posts...
> Loading existing topics...
> 
> importing users...
> 
> importing anonymous users...
> 
> importing categories...
> 
> importing topics and posts...
> 
> Importing attachments from 'postmeta'...
> 
> creating permalinks...
> 
> Updating topic status
> 
> Updating bumped_at on topics
> 
> Updating last posted at on users
> 
> Updating last seen at on users
> 
> Updating first_post_created_at...
> 
> Updating user post_count...
> 
> Updating user topic_count...
> 
> Updating user digest_attempted_at...
> 
> Updating topic users
> 
> Updating post timings
> 
> Updating featured topic users
> 
> Updating featured topics in categories
> 6 / 6 (100.0%) [1771 items/min] ]  
> Resetting topic counters
> 
> Done (00h 00min 00sec)
> 
> ```

[이전 페이지](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349.md?page=1)

[다음 페이지](https://meta.discourse.org/t/use-an-import-script-that-requires-mysql/63349.md?page=3)
