{"id":47,"date":"2006-12-30T16:58:22","date_gmt":"2006-12-30T15:58:22","guid":{"rendered":"http:\/\/blog.blackdown.de\/2006\/12\/30\/47\/"},"modified":"2016-10-29T03:51:01","modified_gmt":"2016-10-29T01:51:01","slug":"chrooting-recent-mysql-versions-on-debian-and-ubuntu","status":"publish","type":"post","link":"https:\/\/blackdown.de\/articles\/chrooting-recent-mysql-versions-on-debian-and-ubuntu\/","title":{"rendered":"Chrooting Recent MySQL Versions on Debian and Ubuntu"},"content":{"rendered":"
I’ve posted a recipe<\/a> for chrooting MySQL on Debian sarge a while ago. These instructions no longer work out of the box for newer MySQL packages from Debian and Ubuntu. The main problem is that the startup script added a few extra checks and script invocations that don’t understand the chroot environment. So here’s an updated plan:<\/p>\n Don’t change the to the I’ve posted a recipe for chrooting MySQL on Debian sarge a while ago. These instructions no longer work out of the box for newer MySQL packages from Debian and Ubuntu. The main problem is that the startup script added a few extra checks and script invocations that don’t understand the chroot environment. So here’s an\n
\/srv\/mysql<\/code> (which is an LVM2<\/a> partition with an ext3 filesystem on my system) for the rest of the text.<\/li>\n
\/etc\/init.d\/mysql stop<\/pre>\n<\/li>\n
mkdir -p \/srv\/mysql\/var\/lib\r\ncp -a \/var\/lib\/mysql \/srv\/mysql\/var\/lib<\/pre>\n<\/li>\n
\/etc\/default\/mysql-chroot<\/code><\/li>\n
\/etc\/init.d\/mysql<\/code>:\n
\n
mysql-chroot<\/a><\/code> script somewhere at the top:\n
…\r\ntest -x \/usr\/sbin\/mysqld || exit 0\r\n\r\n. \/etc\/default\/mysql-chroot<\/strong>\r\n\r\nSELF=$(cd $(dirname $0); pwd -P)\/$(basename $0)\r\n…<\/pre>\n<\/li>\n
\r\n…\r\n# check for diskspace shortage\r\ndatadir=`mysqld_get_param datadir`\r\nif LC_ALL=C BLOCKSIZE= df --portability $CHROOT_DIR<\/strong>$datadir\/. | tail -n 1 | awk '{ exit ($4>4096) }'; then\r\n log_failure_msg "$0: ERROR: The partition with $datadir is too full!"\r\n…<\/pre>\n<\/li>\n
setup_chroot<\/code> right in the start section:\n
…\r\nif mysqld_status check_alive nowarn; then\r\n echo "...already running."\r\nelse\r\n setup_chroot<\/strong>\r\n \/usr\/bin\/mysqld_safe > \/dev\/null 2>&1 &\r\n…<\/pre>\n<\/li>\n
\/var\/run\/mysqld\/mysqld.pid<\/code> disappears after each start. We have to create it each time, otherwise the
stop<\/code> command won’t work properly:\n
…\r\nif mysqld_status check_alive warn; then\r\n log_end_msg 0\r\n ln -sf $CHROOT_DIR\/var\/run\/mysqld\/mysqld.pid \\\r\n \/var\/run\/mysqld<\/strong>\r\n # Now start mysqlcheck or whatever the admin wants.\r\n output=$(\/etc\/mysql\/debian-start)\r\n…<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n
\/etc\/mysql\/debian.cnf<\/code>, change the two
socket<\/code> lines to:\n
socket = \/srv\/mysql\/var\/run\/mysqld\/mysqld.sock<\/pre>\n<\/li>\n
\/etc\/mysql\/my.cnf<\/code>:\n
\n
socket<\/code> line in the
[client]<\/code> section to:\n
socket = \/srv\/mysql\/var\/run\/mysqld\/mysqld.sock<\/pre>\n
socket<\/code> lines in the other sections!<\/p>\n<\/li>\n
chroot = \/srv\/mysql<\/pre>\n
[mysqld]<\/code> section.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n
\/srv\/mysql<\/code> to the log files listed in
\/etc\/logrotate.d\/mysql-server<\/code><\/li>\n
\/usr\/bin\/mysql_upgrade_shell<\/code> use the chrooted socket. Note: Currently these changes must be made each time mysql gets upgraded because upgrades override this file!<\/strong>\n
…\r\n--password=*) password=`echo "$arg" | sed -e 's\/^[^=]*=\/\/'` ;;\r\n--socket=*) socket=`echo "$arg" | sed -e 's\/^[^=]*=\/\/'` ;;<\/strong>\r\n--ldata=*|--data=*|--datadir=*) DATADIR=`echo "$arg" | sed -e 's\/^[^=]*=\/\/'` ;;\r\n…\r\nfi\r\n$bindir\/mysql_fix_privilege_tables --silent --user=$user --password=$password --socket=$socket<\/strong> $args\r\nexit 0\r\n…\r\ncheck_args="--check-upgrade --all-databases --auto-repair --user=$user --password=$password --socket=$socket<\/strong>"\r\n…\r\n$bindir\/mysql_fix_privilege_tables --silent --user=$user --password=$password --socket=$socket<\/strong> $args\r\n…<\/pre>\n<\/li>\n
\/etc\/init.d\/mysql start<\/pre>\n<\/li>\n
\/var\/log\/syslog<\/code> for errors ;-)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"
[→ Read the rest of this entry<\/a>]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3,2,8,16],"tags":[],"yoast_head":"\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n