Mysql-5.5

在 Debian Wheezy 的 chroot 中設置 mySQL

  • July 12, 2014

聽起來像是一個簡單的問題,但是關於 mySQL 需要在 chroot 中執行什麼的文件很少見。

我想我快到了,但我遇到了一個我無法解決的權限問題,mysql-server也不會啟動。

# mysqld [ERROR] Can't find messagefile '/usr/share/mysql/errmsg.sys' [Warning] Can't create test file /var/lib/mysql/***.lower-test [Warning] Can't create test file /var/lib/mysql/***.lower-test mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 2) [ERROR] Aborting [Note]

mysql-server在乾淨的 Debian Wheezy 上安裝了 dotdeb 的軟體包。

沒有 chroot 時它工作正常。

我顯然已經閱讀了 -非常簡潔-關於該選項的官方文件。chroot

我已經閱讀了很多howtos,最後我關注了這個(法語)

我做了什麼

  • 停止mysql伺服器
  • 為 chroot 創建了一個目錄結構:/var/chroot/mysql |____var | |____lib | | |____mysql | | | |____performance_schema | | | |____mysql | |____run | | |____mysqld | |____log |____usr | |____share | | |____zoneinfo (...) | | |____mysql (...) | |____lib | | |____x86_64-linux-gnu |____lib | |____x86_64-linux-gnu |____lib64 |____tmp |____etc
  • 整個樹屬於文件mysql:mysql和目錄rw``rwx
  • tmp有1777個燙髮
  • 移動/var/lib/mysql/var/chroot/mysql/var/lib/mysql並建立了一個符號連結從/var/chroot/mysql/var/lib/mysql/var/lib/mysql
  • /var/run/mysqld
  • 複製/usr/share/mysql/var/chroot/mysql/usr/share/mysql
  • 複製了ldd /usr/sbin/mysqldunder/var/chroot/mysql/path_to_lib

將所有者返回的所有庫,mysql:mysql但保留了主文件系統的權限

  • 複製/etc/localtime/usr/share/zoneinfo我的 chroot
  • 複製/etc/passwd到我的 chroot,只保留mysql使用者的行
  • 已編輯/etc/mysql/my.cnf

[client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 `[mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking skip-show-database bind-address = 127.0.0.1 key_buffer_size = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam_recover_options = BACKUP #max_connections = 100 #max_user_connections = 50 #table_cache = 64 #thread_concurrency = 10 query_cache_limit = 1M query_cache_size = 16M

Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.

slow_query_log = 1 slow_query_log_file = /var/log/slow.log long_query_time = 2 #log-queries-not-using-indexes #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name chroot = /var/lib/mysql/

ssl-ca=/etc/mysql/cacert.pem

ssl-cert=/etc/mysql/server-cert.pem

ssl-key=/etc/mysql/server-key.pem`

[mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completion [isamchk] key_buffer = 16M !includedir /etc/mysql/conf.d/

(我刪除了不相關的評論)

我不得不更改一些選項名稱,因為文件使用了過時的形式(比如key_buffer代替key_buffer_size

無論如何,重要的部分是: datadir=/var/lib/mysql chroot=/var/lib/mysql

datadir應該是相對的,chroot所以它應該指向/var/chroot/mysql/var/lib/mysql(我的數據庫實際儲存的位置)。

儘管它是 的絕對路徑/var/lib/mysql,但它是 的符號連結/var/chroot/mysql/var/lib/mysql,所以它不應該是一個問題。

我得到了什麼

現在,無論我是執行service mysql start還是mysqld(當然是以 root 身份),我都會在螢幕上或在以下位置收到相同的消息/var/log/syslog[ERROR] Can't find messagefile '/usr/share/mysql/errmsg.sys' [Warning] Can't create test file /var/lib/mysql/***.lower-test [Warning] Can't create test file /var/lib/mysql/***.lower-test mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 2) [ERROR] Aborting [Note]

(我也做了一個符號連結/var/chroot/mysql/usr/share/mysql/errmsg.sysfrench/errmsg.sys

看起來好像mysql-server沒有看對地方。

但是為什麼,我該怎麼做才能讓它發揮作用?

哎呀,答案就在問題中。

一定很累,因為正如我所說:

無論如何,重要的部分是: datadir=/var/lib/mysql chroot=/var/lib/mysql

但是,如果我想與自己保持一致,chroot必須是/var/chroot/mysql

所以正確的設置是: datadir=/var/lib/mysql chroot=/var/chroot/mysql 確實有效!

希望這對嘗試在 chroot 中執行 mysql 的人有用。

引用自:https://dba.stackexchange.com/questions/71191