记一次mysqlserverclone

昨天在学习mysql的时候,看到mysqlserverclone这个工具,尝试了下居然报错

     ~ mysqlserverclone --basedir=/usr/local/Cellar/mysql/5.6.20_1 \
    >   --mysqld="--log-bin=mysql-bin --report-port=3313 --report-host=localhost" \
    >   --new-port=3313 \
    >   --new-data=/tmp/mysql_temp_3313 \
    >   --new-id=103 --delete-data \
    >   --write-command /tmp/start_mysql_3313 --verbose
    # WARNING: Root password for new instance has not been set.
    # Cloning the MySQL server located at /usr/local/Cellar/mysql/5.6.20_1.
    # Configuring new instance...
    # Locating mysql tools...
    ERROR: Cannot find location of mysql_system_tables.sql.

全局查找下这个文件

 sudo find  / -name 'mysql_system_tables*'
/usr/local/Cellar/mysql/5.6.20_1/share/mysql/mysql_system_tables.sql
/usr/local/Cellar/mysql/5.6.20_1/share/mysql/mysql_system_tables_data.sql

由于环境是用brew装的,目录有些特殊
看下mysqlserverclone的代码发现是引用了别的包

#!/usr/bin/python
#
# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
 
"""
This file contains the clone server utility which launches a new instance
of an existing server.
"""
 
from mysql.utilities.common.tools import check_python_version
 
# Check Python version compatibility
check_python_version()
 
import os.path
import sys
 
from mysql.utilities import exception
from mysql.utilities.command import serverclone
from mysql.utilities.common.ip_parser import parse_connection
from mysql.utilities.common.tools import check_connector_python
from mysql.utilities.common.options import (add_basedir_option, add_verbosity,
                                            get_ssl_dict,
                                            check_dir_option,
                                            setup_common_options,
                                            check_password_security)
from mysql.utilities.common.server import Server
 
...... 省略
 
    try:
        serverclone.clone_server(conn, options)
    except exception.UtilError:
        _, e, _ = sys.exc_info()
        print("ERROR: {0}".format(e.errmsg))
        sys.exit(1)
 
    sys.exit()

继续全局查找

sudo find / -name 'serverclone*'
Password:
/Library/Python/2.7/site-packages/mysql/utilities/command/serverclone.py

查看serverclone.py文件

138     mysqld_path = get_tool_path(basedir, "mysqld")
139     mysqladmin_path = get_tool_path(basedir, "mysqladmin")
140     mysql_basedir = get_tool_path(basedir, "share/english/errgmsg.sys",
141                                   False, False)
142     mysql_basedir = basedir
143     if os.path.exists(os.path.join(basedir, "local/mysql/share/")):
144         mysql_basedir = os.path.join(mysql_basedir, "local/mysql/")
145     # for source trees
146     elif os.path.exists(os.path.join(basedir, "/sql/share/english/")):
147         mysql_basedir = os.path.join(mysql_basedir, "/sql/")
148     system_tables = get_tool_path(basedir, "mysql_system_tables.sql", False)
149     system_tables_data = get_tool_path(basedir, "mysql_system_tables_data.sql",
150                                        False)
151     test_data_timezone = get_tool_path(basedir, "mysql_test_data_timezone.sql",
152                                        False)
153     help_data = get_tool_path(basedir, "fill_help_tables.sql", False)
154

发现脚本是在basedir目录下直接查找。可能由于我的环境安装文档导致目录不一样,简单修改下代码

  system_tables = get_tool_path(basedir, "share/mysql/mysql_system_tables.sql", False)
  system_tables_data = get_tool_path(basedir, "share/mysql/mysql_system_tables_data.sql",
                                     False)
  test_data_timezone = get_tool_path(basedir, "share/mysql/mysql_test_data_timezone.sql",
                                     False)
  help_data = get_tool_path(basedir, "share/mysql/fill_help_tables.sql", False)

在次运行

 mysqlserverclone --server=root@localhost \
  --mysqld="--log-bin=mysql-bin --report-port=3313 --report-host=localhost" \
  --new-port=3313 \
  --new-data=/tmp/mysql_temp_3313 \
  --new-id=103 \
  --delete-data  -vvv
# WARNING: Root password for new instance has not been set.
# Cloning the MySQL server running on localhost.
# Configuring new instance...
# Locating mysql tools...
# Location of files:
#                       mysqld: /usr/local/Cellar/mysql/5.6.20_1/bin/mysqld
#                   mysqladmin: /usr/local/Cellar/mysql/5.6.20_1/bin/mysqladmin
# Location of files:
#                       mysqld: /usr/local/Cellar/mysql/5.6.20_1/bin/mysqld
#                   mysqladmin: /usr/local/Cellar/mysql/5.6.20_1/bin/mysqladmin
#      mysql_system_tables.sql: /usr/local/Cellar/mysql/5.6.20_1/share/mysql/mysql_system_tables.sql
# mysql_system_tables_data.sql: /usr/local/Cellar/mysql/5.6.20_1/share/mysql/mysql_system_tables_data.sql
# mysql_test_data_timezone.sql: /usr/local/Cellar/mysql/5.6.20_1/share/mysql/mysql_test_data_timezone.sql
#         fill_help_tables.sql: /usr/local/Cellar/mysql/5.6.20_1/share/mysql/fill_help_tables.sql
# Setting up empty database and mysql tables...
2014-09-21 00:54:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-21 00:54:17 47301 [Warning] Setting lower_case_table_names=2 because file system for /tmp/mysql_temp_3313/ is case insensitive
2014-09-21 00:54:17 47301 [Note] Plugin 'FEDERATED' is disabled.
2014-09-21 00:54:17 47301 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-09-21 00:54:17 47301 [Note] InnoDB: The InnoDB memory heap is disabled
2014-09-21 00:54:17 47301 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-09-21 00:54:17 47301 [Note] InnoDB: Memory barrier is not used
2014-09-21 00:54:17 47301 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-09-21 00:54:17 47301 [Note] InnoDB: Using CPU crc32 instructions
2014-09-21 00:54:17 47301 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-09-21 00:54:17 47301 [Note] InnoDB: Completed initialization of buffer pool
2014-09-21 00:54:17 47301 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-09-21 00:54:17 47301 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-09-21 00:54:17 47301 [Note] InnoDB: Database physically writes the file full: wait...
2014-09-21 00:54:17 47301 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-09-21 00:54:17 47301 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-09-21 00:54:17 47301 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-09-21 00:54:17 47301 [Warning] InnoDB: New log files created, LSN=45781
2014-09-21 00:54:17 47301 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-09-21 00:54:17 47301 [Note] InnoDB: Doublewrite buffer created
2014-09-21 00:54:17 47301 [Note] InnoDB: 128 rollback segment(s) are active.
2014-09-21 00:54:17 47301 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-09-21 00:54:17 47301 [Note] InnoDB: Foreign key constraint system tables created
2014-09-21 00:54:17 47301 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-09-21 00:54:17 47301 [Note] InnoDB: Tablespace and datafile system tables created.
2014-09-21 00:54:17 47301 [Note] InnoDB: Waiting for purge to start
2014-09-21 00:54:17 47301 [Note] InnoDB: 5.6.20 started; log sequence number 0
2014-09-21 00:54:17 47301 [Note] RSA private key file not found: /tmp/mysql_temp_3313//private_key.pem. Some authentication plugins will not work.
2014-09-21 00:54:17 47301 [Note] RSA public key file not found: /tmp/mysql_temp_3313//public_key.pem. Some authentication plugins will not work.
2014-09-21 00:54:18 47301 [Note] Binlog end
2014-09-21 00:54:18 47301 [Note] InnoDB: FTS optimize thread exiting.
2014-09-21 00:54:18 47301 [Note] InnoDB: Starting shutdown...
2014-09-21 00:54:19 47301 [Note] InnoDB: Shutdown completed; log sequence number 1625977
# Starting new instance of the server...
# Startup command for new server:
/usr/local/Cellar/mysql/5.6.20_1/bin/mysqld --no-defaults --datadir=/tmp/mysql_temp_3313 --tmpdir=/tmp/mysql_temp_3313 --pid-file=/tmp/mysql_temp_3313/clone.pid --port=3313 --server-id=103 --basedir=/usr/local/Cellar/mysql/5.6.20_1 --socket=/tmp/mysql_temp_3313/mysql.sock --log-bin=mysql-bin --report-port=3313 --report-host=localhost
# Testing connection to new instance...
2014-09-21 00:54:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-21 00:54:19 47302 [Warning] Setting lower_case_table_names=2 because file system for /tmp/mysql_temp_3313/ is case insensitive
2014-09-21 00:54:19 47302 [Note] Plugin 'FEDERATED' is disabled.
2014-09-21 00:54:19 47302 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-09-21 00:54:19 47302 [Note] InnoDB: The InnoDB memory heap is disabled
2014-09-21 00:54:19 47302 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-09-21 00:54:19 47302 [Note] InnoDB: Memory barrier is not used
2014-09-21 00:54:19 47302 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-09-21 00:54:19 47302 [Note] InnoDB: Using CPU crc32 instructions
2014-09-21 00:54:19 47302 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-09-21 00:54:19 47302 [Note] InnoDB: Completed initialization of buffer pool
2014-09-21 00:54:19 47302 [Note] InnoDB: Highest supported file format is Barracuda.
2014-09-21 00:54:19 47302 [Note] InnoDB: 128 rollback segment(s) are active.
2014-09-21 00:54:19 47302 [Note] InnoDB: Waiting for purge to start
2014-09-21 00:54:19 47302 [Note] InnoDB: 5.6.20 started; log sequence number 1625977
2014-09-21 00:54:19 47302 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c3b806de-40e6-11e4-af67-dc666be53b76.
2014-09-21 00:54:19 47302 [Note] RSA private key file not found: /tmp/mysql_temp_3313//private_key.pem. Some authentication plugins will not work.
2014-09-21 00:54:19 47302 [Note] RSA public key file not found: /tmp/mysql_temp_3313//public_key.pem. Some authentication plugins will not work.
2014-09-21 00:54:19 47302 [Note] Server hostname (bind-address): '*'; port: 3313
2014-09-21 00:54:19 47302 [Note] IPv6 is available.
2014-09-21 00:54:19 47302 [Note]   - '::' resolves to '::';
2014-09-21 00:54:19 47302 [Note] Server socket created on IP: '::'.
2014-09-21 00:54:19 47302 [Note] Event Scheduler: Loaded 0 events
2014-09-21 00:54:19 47302 [Note] /usr/local/Cellar/mysql/5.6.20_1/bin/mysqld: ready for connections.
Version: '5.6.20-log'  socket: '/tmp/mysql_temp_3313/mysql.sock'  port: 3313  Homebrew
# trying again...
# Success!
# Connection Information:
#  -uroot --socket=/tmp/mysql_temp_3313/mysql.sock
#...done.
此条目发表在 MySQL 分类目录。将固定链接加入收藏夹。

评论功能已关闭。