Skip to content

Instantly share code, notes, and snippets.

@wxianfeng
Created June 7, 2012 08:24
Show Gist options
  • Save wxianfeng/2887394 to your computer and use it in GitHub Desktop.
Save wxianfeng/2887394 to your computer and use it in GitHub Desktop.
mysql 配置两个实例
# 单台机器配置两个mysql实例,UBUNTU
# 把原先的mysqld变成mysqld1,然后新建一个mysqld2
>vim /etc/mysql/my.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user=root
password=root
[mysqld1]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
log-error = /var/log/mysql.err
port = 3306
basedir = /usr
datadir = /var/lib/mysql
bind-address = 192.168.10.107
[mysqld2]
user = mysql
pid-file = /tmp/mysqld2.pid # 不一样
socket = /tmp/mysqld2.sock # 不一样
log-error = /var/log/mysql.err
port = 3307 # 不一样
basedir = /usr
datadir = /data/mysql # 不一样
bind-address = 192.168.10.107
# 添加/data/mysql 的权限
>sudo vim /etc/apparmor.d/usr.sbin.mysqld
/data/mysql/ r,
/data/mysql/** rwk,
>sudo /etc/init.d/apparmor restart
>sudo /usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql
# 可以copy原来mysql data
>cp -r /var/lib/mysql /data/
# 查看状态
wxianfeng@wxianfeng:/data/projects/entos$ sudo /usr/bin/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
# 全部启动
>sudo /usr/bin/mysqld_multi start
# 启动mysqld1
>sudo /usr/bin/mysqld_multi start 1
# 启动mysqld2
>sudo /usr/bin/mysqld_multi start 2
# 全部stop
>sudo /usr/bin/mysqld_multi stop
# 进 mysql console, mysqld2
>mysql -uroot -p -S /tmp/mysqld2.sock
# 进 mysql console, mysqld1
>mysql -uroot -p -S /var/run/mysql/mysqld.sock
# 单机主从配置
>vim /etc/mysql/my.cnf
[mysqld1]
log-bin=mysql-bin
server-id=107
[mysqld2]
log_bin=mysql-bin
server_id=2
# 主
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000018 | 107 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
# 从
mysql> change master to master_host='192.168.10.107', master_user='slave', master_password='netposa', master_log_file='mysql-bin.000018', master_log_pos=107;
mysql>start slave;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment