yl197837 发表于 2018-10-2 07:26:20

安装两个mysql

  今天准备在外网多安装一个mysql来测试新版开发的网站--使用不同数据库连接.
  不用说,路径,端口,socket肯定要不相同
  # tar xvf mysql-5.0.41.tar.gz
  # cd mysql-5.0.41/
  # mkdir /usr/local/mysql5
  # ./configure --prefix=/usr/local/mysql5 --localstatedir=/var/lib/mysql5
  --with-comment=Source --with-server-suffix=-Linuxtone.Org --with-mysqld-user=mysql --without-debug --with-big-tables --with- --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-plugins=all --without-ndb-debug
  make
  make install
  # ll /var/lib/mysql5 看看有没有产生这个目录,没有就新建一个mkdir /var/lib/mysql5
  初始化数据库
  # /usr/local/mysql5/bin/mysql_install_db
  # cd /usr/local/mysql5
  授权
  # chown -R mysql:mysql .
  # chown -R mysql:mysql /var/lib/mysql5
  #chgrp -R mysql .
  复制配置文件到/etc目录
  # cp share/mysql/my-huge.cnf /etc/my5.cnf
  开机自行启动服务,将脚本复制到/etc/rc.d/init.d/
  # cp share/mysql/mysql.server /etc/rc.d/init.d/mysql5
  mysql服务脚本作适当的修改,可以参照network服务脚本格式,如果不修改有时候不能识别
  #
  # head -15 /etc/rc.d/init.d/network
  #! /bin/bash
  #
  # network       Bring up/down networking
  #
  # chkconfig: 2345 10 90
  # description: Activates/Deactivates all network interfaces configured to \
  #            start at boot time.
  #
  ### BEGIN INIT INFO
  # Provides: $network
  ### END INIT INFO
  # Source function library.
  . /etc/init.d/functions
  ————————————————————————————————--
  修改后的mysql5服务脚本
  # head -15 /etc/rc.d/init.d/mysql5
  #!/bin/sh
  #
  # mysql       Bring up/down mysql
  #
  # chkconfig: 2345 86 10
  # description: Activates/Deactivates all network interfaces configured to \
  #            start at boot time.
  #
  ### BEGIN INIT INFO
  # Provides: $mysql
  ### END INIT INFO
  # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
  # This file is public domain and comes with NO WARRANTY of any kind
  在第5行注意启动级别不能冲突---> # chkconfig: 2345 86 10
  搜索修改:
  1.datadir=/var/lib/mysql5
  2.conf=/etc/my5.cnf
  3.把$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &替换为
  $bindir/mysqld_safe --defaults-file=/etc/my5.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
  保存退出,添加服务
  # chkconfig --add mysql5
  修改/etc/my5.cnf
  端口:你想要的端口,条件是不能和其他服务冲突
  port = 6606
  socket = /tmp/mysql5.sock
  ...............下面同样
  启动服务
  # service mysql5 start
  Starting MySQL                                             [确定]
  两个端口出来了
  # netstat -ntlp | grep mysql
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1924/mysqld
  tcp      0      0 0.0.0.0:6606                0.0.0.0:*                   LISTEN      1976/mysqld
  登录:
  先前安装的不必指定socket,但是后装的要指定socket,
  改下密码,我喜欢这种方式改.如果忘掉mysql密码也可这样重置mysql的root密码
  停掉mysql服务(两个),因为等一下该的时候会冲突,/mysqld_safe & 启动是默认是3306端口
  # service mysql stop
  Shutting down MySQL..                                    [确定]
  # service mysql5 stop
  Shutting down MySQL                                        [确定]
  # /usr/local/mysql5/bin/mysqld_safe --skip-grant-tables &
  # netstat -ntlp | grep mysql
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3087/mysqld
  # mysql
  Welcome to the MySQL monitor.Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.0.41-Community-log Source
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql> show databases;
  +--------------------+
  | Database         |
  +--------------------+
  | information_schema |
  | mysql            |
  | test               |
  | ubunt            |
  +--------------------+
  4 rows in set (0.00 sec)
  mysql> use mysql;
  mysql> update user set password=password('newpasswd') where user='root';
  Query OK, 3 rows affected (0.01 sec)
  Rows matched: 3Changed: 3Warnings: 0
  修改成功,刷新权限...(括号里是要想修改的密码).
  mysql> flush privileges;
  Query OK, 0 rows affected (0.00 sec)
  重启服务,
  # service mysql5 restart
  Shutting down MySQLSTOPPING server from pid file /var/lib/mysql5/station188.cluster.com.pid
  110428 21:01:26mysqld ended
  [确定]
  Starting MySQL                                             [确定]
  +Done                  /usr/local/mysql5/bin/mysqld_safe --skip-grant-tables
  查看端口
  # netstat -ntlp | grep mysql
  tcp      0      0 0.0.0.0:6606                0.0.0.0:*                   LISTEN      3163/mysqld
  登录
  # mysql -uroot -pnewpasswd --socket=/tmp/mysql5.sock
  Welcome to the MySQL monitor.Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.0.41-Community-log Source
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql> show databases;
  +--------------------+
  | Database         |
  +--------------------+
  | information_schema |
  | mysql            |
  | test               |
  | ubunt            |
  +--------------------+
  4 rows in set (0.00 sec)
  另一个mysql登录
  # service mysql start
  Starting MySQL                                             [确定]
  # netstat -ntlp | grep mysql
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3213/mysqld
  tcp      0      0 0.0.0.0:6606                0.0.0.0:*                   LISTEN      3163/mysqld
  # mysql -uroot -p123456
  Welcome to the MySQL monitor.Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.0.41-log Source distribution
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql> show databases;
  +--------------------+
  | Database         |
  +--------------------+
  | information_schema |
  | mysql            |
  | redhat             |
  | test               |
  +--------------------+
  4 rows in set (0.00 sec)

页: [1]
查看完整版本: 安装两个mysql