如果你在Linux系統下需要安裝兩個MySQL數據庫,你可以按照以下步驟進行:
1. 首先,你需要下載并安裝兩個不同的MySQL安裝包,例如: mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz 2. 解壓安裝包,例如: tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ tar -Jxvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz -C /usr/local/ 3. 重命名解壓后的兩個目錄: mv /usr/local/mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql5 mv /usr/local/mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql8 4. 創建兩個MySQL數據目錄: mkdir /usr/local/mysql5/data/ mkdir /usr/local/mysql8/data/ 5. 拷貝兩個不同的MySQL配置文件: cp /usr/local/mysql5/support-files/my-default.cnf /etc/my5.cnf cp /usr/local/mysql8/support-files/mysql.server /etc/my8.cnf 6. 修改兩個配置文件中的以下參數: [mysqld] basedir = /usr/local/mysql5 datadir = /usr/local/mysql5/data port = 3306 socket = /var/run/mysqld/mysqld5.sock [mysqld] basedir = /usr/local/mysql8 datadir = /usr/local/mysql8/data port = 3307 socket = /var/run/mysqld/mysqld8.sock 7. 創建兩個用戶和組: groupadd mysql5 useradd -r -g mysql5 -s /bin/false mysql5 groupadd mysql8 useradd -r -g mysql8 -s /bin/false mysql8 8. 初始化兩個數據庫: /usr/local/mysql5/bin/mysqld --defaults-file=/etc/my5.cnf --initialize --user=mysql5 --basedir=/usr/local/mysql5 --datadir=/usr/local/mysql5/data /usr/local/mysql8/bin/mysqld --defaults-file=/etc/my8.cnf --initialize --user=mysql8 --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data 9. 啟動兩個MySQL服務器: /usr/local/mysql5/bin/mysqld_safe --defaults-file=/etc/my5.cnf --user=mysql5 & /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my8.cnf --user=mysql8 & 10. 連接并操作兩個數據庫: mysql -uroot -p -S /var/run/mysqld/mysqld5.sock -P3306 mysql -uroot -p -S /var/run/mysqld/mysqld8.sock -P3307