-1

我一直在尝试在 ubuntu 上创建多个 mysql 实例。这些是我遵循的步骤。

mv /etc/init.d/mysql /etc/init.d/mysql_mono.server
cp /usr/share/mysql/mysqld_multi.server /etc/init.d/mysql

使用您最喜欢的文本编辑器,编辑 /etc/init.d/mysql,然后找到以下行:

basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin

并更改为:

basedir=/usr
bindir=/usr/bin

如果您在 localhost 中有 root 密码,请编辑文件 /usr/bin/mysqld_multi,然后找到以下行:

$opt_password = undef()

并更改为:

$opt_password = "password"

通过'root'@'localhost'密码更改“密码”。

现在为每个额外的 mysqld 实例创建一个数据库目录:

# cp -pr /var/lib/mysql /var/lib/mysql1
# cp -pr /var/lib/mysql /var/lib/mysql2

我的配置文件(my.cnf)是:

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0



[mysqld1]
user = root
pid-file = /var/run/mysqld1.pid
socket = /var/run/mysqld1.sock
port = 3301
datadir = /var/lib/mysql1
log = /var/log/mysql/mysql1.log
server-id = 1
log_bin = /var/log/mysql/mysql1-bin.log

[mysqld2]
user = root
pid-file = /var/run/mysqld2.pid
socket = /var/run/mysqld2.sock
port = 3302
datadir = /var/lib/mysql2
log = /var/log/mysql/mysql2.log
server-id = 2
log_bin = /var/log/mysql/mysql2-bin.log


# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1

log_error                = /var/log/mysql/error.log


[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer      = 16M


``!includedir /etc/mysql/conf.d/

当我运行以下命令时,我仍然收到此错误:

mysql --socket=/var/run/mysqld1.sock -uroot


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld1.sock' (2)
4

1 回答 1

0

通过http://dev.mysql.com/doc/refman/5.5/en/multiple-unix-servers.html

一种方法是在 Unix 上运行多个 MySQL 实例,即编译具有不同默认 TCP/IP 端口和 Unix 套接字文件的不同服务器,以便每个服务器侦听不同的网络接口。为每个安装在不同的基本目录中编译也会自动为每个服务器生成一个单独的、已编译的数据目录、日志文件和 PID 文件位置。

假设现有 5.1 服务器配置了默认 TCP/IP 端口号 (3306) 和 Unix 套接字文件 (/tmp/mysql.sock)。要将新的 5.5.35 服务器配置为具有不同的操作参数,请使用如下 CMake 命令:

shell> cmake . -DMYSQL_TCP_PORT=port_number \
             -DMYSQL_UNIX_ADDR=file_name \
             -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.35
于 2013-10-04T08:58:18.990 回答