機器主~master-192.168.73.76_5.7.22測試
先查看目前使用的版本
[root@rosalie-mysql02 data]# mysql -V
mysql Ver 8.0.16 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
因為要一台機器啟動兩個mysql,且連結的db也庫不同,看需求,可以同版本,亦可不同版本
這邊我們用同一個版本所以(紅色指令)
[root@rosalie-mysql02]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar
[root@rosalie-mysql02 ~]# tar xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar
mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.16-linux-glibc2.12-x86_64.tar.xz
mysql-test-8.0.16-linux-glibc2.12-x86_64.tar.xz
[root@rosalie-mysql02 ~]# tar -xJf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
[root@rosalie-mysql02 ~]# mv mysql-8.0.16-linux-glibc2.12-x86_64 /usr/local/mysql_3308
1.先下載 MYSQL 8.0.16
2.解打包,會產生三個檔案,主要是 mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
3.解tar.xz的壓縮檔
4.將解好的壓縮檔移動到/usr/local/mysql_3308 因原本沒有,所以移動會自動更名---這是啟動的位置
這是原本的my.cnf的設定
[mysqld]
# 原本就啟動中的DB~my.cnf的基本設定
datadir =/data/mysql
basedir =/usr/local/mysql
socket =/tmp/mysql.sock
log_bin =mysql-bin
port = 3306
server-id = 01
log_error =/data/mysql/rosalie-mysql02.err
pid-file =/data/mysql/rosalie-mysql02.pid
可以由上看到原DB其 datadir資料夾路徑為/data/mysql
所以先創另一個資料夾以不同PORT-3308來區別
[root@rosalie-mysql01 data] # mkdir /data/mysql_3308
[root@rosalie-mysql01 data] # chown mysql:mysql /data/mysql_3308
然後考備原my.cnf的設定到/etc/下,自行命名不同的名字
[root@rosalie-mysql01 data] # cp /etc/my.cnf /etc/mysql_3308_my.cnf
接著編輯3308 PORT的 my.cnf
[root@rosalie-mysql01 data] # vi /etc/mysql_3308_my.cnf
更改參數如下
[mysqld]------第二台mysql的my.cnf
datadir =/data/mysql_3308
basedir =/usr/local/mysql_3308
socket =/tmp/mysql_3308.sock
log_bin =mysql-bin
port = 3308
server-id = 11
log_error =/data/mysql_3308/rosalie-mysql02.err
pid-file =/data/mysql_3308/rosalie-mysql02.pid
port = 3308
這一步是在剛剛安裝建立的目錄下面,初始化數據庫。(紅色是指令,紫色是初始化後產生的帳密)
[root@rosalie-mysql02 local]# /usr/local/mysql_3308/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql_3308 --datadir=/data/mysql_3308
2019-06-03T07:09:54.333434Z 0 [System] [MY-013169] [Server] /usr/local/mysql_3308/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 2523
2019-06-03T07:09:55.964734Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uWJbs%lJw9ZW
2019-06-03T07:09:56.739579Z 0 [System] [MY-013170] [Server] /usr/local/mysql_3308/bin/mysqld (mysqld 8.0.16) initializing of server has completed
接著啟動DB--- 指令下之後會停住,但已啟動,可關閉或是再開一個視窗
[root@rosalie-mysql01 etc]# mysqld_safe --defaults-file=/etc/mysql_3308_my.cnf &
登入方式 ,指令輸入完成後,再輸入密碼即可登入
[root@rosalie-mysql01 etc]# mysql -uroot -p -P3308 --socket=/tmp/mysql_3308.sock
登入後,必需先改密碼才能使用!!
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user user() identified by "12345";
Query OK, 0 rows affected (0.06 sec)
#會看到是完全新的數據庫,不影響原本機器內的另一個數據庫,也不需要重啟MYSQL
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
查看啟動的端口有哪些,出現3306及3308
[root@rosalie-mysql02 ~]# netstat -tulpn
Active Internet connections (only servers)
略
.
tcp 0 0 :::3306 :::* LISTEN 1308/mysqld
tcp 0 0 :::3308 :::* LISTEN 2807/mysqld
.
略
若要關閉3308
[root@rosalie-mysql02 tmp]# /usr/local/mysql_3308/bin/mysqladmin -uroot -p -S /tmp/mysql_3308.sock shutdown
再次查看端口 ,只剩下3306
[root@rosalie-mysql02 tmp]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1420/sshd
.
.
tcp 0 0 :::3306 :::* LISTEN 1308/mysqld
沒有留言:
張貼留言