日期:2014-05-16  浏览次数:21017 次

一机多实体mysql
1.卸载mysql-libs 是不卸载crontab

  rpm -e --nodeps mysql-libs-5.1.*

  注意,一定要加:--nodeps,否则也会将crontab等依赖卸掉,这样就不是我们的初衷了。

  然后继续安装MYSQL,最后,检查测试MYSQL和crontab,都可以正常工作了

2.MySQL-server-5.5.28-1.linux2.6.x86_64.rpm安装:

   yum install gcc libaio.so.1 libaio
  
   rpm -ivh MySQL-server-5.5.28-1.linux2.6.x86_64.rpm
  
   rpm -ivh MySQL-client-5.5.28-1.linux2.6.x86_64.rpm

3.初始化数据库:

  /usr/bin/mysql_install_db

4.复制数据库

  cd /var/lib/

  cp mysql mysql2 (需要几个实体就复制几份)
 
5.配置my.cnf (没有my.cnf 就从/usr/share/mysql/复制)

  #vim /etc/my.cnf  (cd /usr/share/mysql/)

  [mysqld_multi]

  mysqld = /usr/bin/mysqld_safe

  mysqladmin = /usr/local/mysql/bin/mysqladmin

  user    = multi

  password  = xxxxxx

  [mysqld1]

  datadir = /var/lib/mysql

  socket = /var/lib/mysql/mysql.sock

  pid-file = /var/lib/mysql/mysqld.pid

  user = mysql

  port = 3306

  server-id = 100

  #log-bin = mysql-bin

  #log-error = /var/log/mysqld1.log

  [mysqld2]

  datadir = /var/lib/mysql2

  socket = /var/lib/mysql2/mysql.sock

  pid-file = /var/lib/mysql2/mysqld.pid

  user = mysql

  port = 3307

  server-id = 200

  #log-bin = mysql-bin

  初试化

  /usr/bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql

  /usr/bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql2

6.启动mysql:

  cd /usr/bin

  ./mysqld_multi start 启动所以数据库

  ./mysqld_multi start 1,2 启动1,2数据库

  ./mysqld_multi start 1-5 启动1到5数据库

  ./mysqld_multi report  查看


7.关闭数据库设置:登陆数据库添加关闭数据库的账号和权限

  添加系统账号:

  useradd multi -s /sbin/nologin

  passwd multi xxxxx

  usermode -G mysql multi 加入到mysql组中

  进入数据库1,2添加用户

  mysql -u root -p -S /var/lib/mysql/mysql.sock

  grant shutdown on *.* to multi@localhost identified by 'xxxxx';

flush privileges;

  mysql -u root -p -S /var/lib/mysql2/mysql.sock

  grant shutdown on *.* to multi@localhost identified by 'xxxxx';

  flush privileges;

  ...以此修改下去

  以上2步为给multi_admin关闭数据库的权限,否则mysqld_multi命令关闭不了数据

  库,如果这样,那么只能:

  mysqladmin -u root -S /var/lib/mysql1/mysql.sock shutdown  关闭了

  现在就可以关闭数据库了:

  cd /usr/bin

./mysqld_multi stop 关闭所以数据库

./mysqld_multi stop 1 关闭数据库1

./mysqld_multi stop 1-5 关闭数据库1到5