一臺機器上安裝兩個Mysql

花花蘑菇發表於2016-08-24

網上大部分文件都是用mysql_multi來實現一個機器上跑多個mysql例項的。但是不知道為什麼,我按照他們的做法就是不成功。以後再嘗試吧。

現在就用最簡單的方法,在一個機器上安裝兩個mysql。安裝方式同安裝一個mysql沒什麼太大區別。

     tar  -zxvf  mysql-5.6.24.tar.gz

    cd  mysql-5.6.24

第一個Mysql,埠3306:

         cmake \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DWITH_MYISAM_STORAGE_ENGINE=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWITH_MEMORY_STORAGE_ENGINE=1 \
 -DWITH_READLINE=1 \
 -DENABLED_LOCAL_INFILE=1 \
 -DMYSQL_DATADIR=/usr/local/mysql/data \
 -DMYSQL_USER=mysql \
 -DMYSQL_TCP_PORT=3306

         make

         make install

第二個Mysql,埠3307:

            cmake \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 \
 -DMYSQL_UNIX_ADDR=/usr/local/mysql3307/mysql.sock \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DWITH_MYISAM_STORAGE_ENGINE=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWITH_MEMORY_STORAGE_ENGINE=1 \
 -DWITH_READLINE=1 \
 -DENABLED_LOCAL_INFILE=1 \
 -DMYSQL_DATADIR=/usr/local/mysql3307/data \
 -DMYSQL_USER=mysql \
 -DMYSQL_TCP_PORT=3307

         make

         make install

更改屬主:

        chown -R mysql:mysql /usr/local/mysql
        chown -R mysql:mysql /usr/local/mysql/data

        chown -R mysql:mysql /usr/local/mysql3307
        chown -R mysql:mysql /usr/local/mysql3307/data

初始化:

        cd /usr/local/mysql
        ./scripts/mysql_install_db --user=mysql

        cd /usr/local/mysql3307
        ./scripts/mysql_install_db --user=mysql

新增到服務列表:

        cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
        cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf3306

        cp /usr/local/mysql3307/support-files/mysql.server /etc/init.d/mysql3307
        cp /usr/local/mysql3307/support-files/my-default.cnf /etc/my.cnf3307

啟服務:

        service  mysql  start
        service mysql3307  start

檢視服務是否啟動:

         netstat -tlnap|grep mysql

更改root使用者的密碼:

         ./usr/local/mysql/bin/mysqladmin -u root password 'root';

         ./usr/local/mysql3307/bin/mysqladmin -u root password 'root';

登陸:

        mysql -S /usr/local/mysql/mysql.sock -P 3306 -uroot -p

        mysql -S /usr/local/mysql3307/mysql.sock -P 3307 -uroot -p

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28497416/viewspace-2123929/,如需轉載,請註明出處,否則將追究法律責任。

相關文章