为轻便地学习mysql主从,就搞个单机启动多实例来操作,记录下操作步骤:
1、编辑一个新的 f 文件用于新的server
复制代码 代码如下:
cp -p /etc/f /etc/f###-p是保留权限
修改配置,防止和原有配置冲突。主要需要修改的有:
端口(port)、socket 文件路径 (socket)、数据文件路径 (datadir);
如果用到 InnoDB(一般都会用到),则要修改 InnoDB 数据文件路径 (innodb_data_home_dir)、InnoDB 日志文件路径 (innodb_log_group_home_dir);
如果用到replication时,还要修改server的唯一id (server-id)、下载到master的binlog的存放路径 (relay-log)等。其他配置修改,则根据具体情况自行调整。
以我测试环境修改为例:
less /etc/f
复制代码 代码如下:
[mysqld]
datadir=/data/dbdata/
skip-name-resolve
#lower_case_table_names=1
character-set-server = utf8
event_scheduler=ON
skip-name-resolve
innodb_file_per_table=1
log_bin_trust_function_creators=1
wait_timeout=300
interactive_timeout=300
#federated
# generic configuration options
port = 3306
socket = /usr/local/mysql/tmp/mysql.sock
修改f
vi /etc/f
复制代码 代码如下:
[mysqld]
datadir=/data/dbdata3307/
skip-name-resolve
#lower_case_table_names=1
character-set-server = utf8
event_scheduler=ON
skip-name-resolve
innodb_file_per_table=1
log_bin_trust_function_creators=1
wait_timeout=300
interactive_timeout=300
#federated
# generic configuration options
port = 3307
socket = /tmp/mysql3307.sock
2、初始化DB
复制代码 代码如下:
/usr/local/mysql/bin/mysql_install_db --defaults-file=/etc/f
chown -R mysql.mysql /data/dbdata3307
3、启动mysql
复制代码 代码如下:
mysqld_safe --defaults-file=/etc/f &
---登陆
mysql -S /tmp/mysql3307.sock
mysql -S /tmp/mysql3307.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.50-log Source distribution
Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@(none) 15:12>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
>>> 更多内容,请访问:mysql主从复制、mysql主从同步系列教程