執行多個 MySQL CentOS7 實例
我需要在我的 PC 上執行多個 MySQL 實例。我這樣做了:
yum install mariadb-server mariadb
=> 安裝 mysql
mysql_install_db --datadir=/var/lib/mysql
=> 使用 mysql_install_db 為第一個實例創建 datadir
mysql_install_db --datadir=/var/lib/mysql2
=> 使用 mysql_install_db 為第二個實例創建 datadir
chown -R mysql:mysql /var/lib/mysql
chown 所有者使用者:所有者組
chown -R mysql:mysql /var/lib/mysql2
chown 所有者使用者:所有者組然後我為多個實例修改了 my.cnf 文件:
[client] #password = your_password port = 3306 socket = /var/lib/mysql/mysql.sock # Here follows entries for some specific programs # The MariaDB server [mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin [mysqld0] port = 3306 socket = /var/lib/mysql/mysql.sock pid-file = /var/run/mysqld/mysqld.pid datadir = /var/lib/mysql server-id = 1 log-bin = mysql-bin binlog_format = mixed [mysqld2] port = 3307 socket = /var/lib/mysql2/mysql.sock pid-file = /var/run/mysqld/mysqld2.pid datadir = /var/lib/mysql2 server_id = 2 skip-log-bin
然後我使用了這個命令
mysqld_multi report
並得到了這個:Reporting MySQL servers MySQL server from group: mysqld0 is not running MySQL server from group: mysqld2 is not running
然後我使用
mysqld_multi start
andmysqld_multi report
並再次收到相同的消息:Reporting MySQL servers MySQL server from group: mysqld0 is not running MySQL server from group: mysqld2 is not running
我在網上沖浪,發現了這個解決方案multiple instances和mysqld_multi。但我沒有找到解決問題的任何關鍵。我將如何執行我的實例?
我發現了為什麼我無法啟動我的兩個實例。有必要發表評論
$$ client $$文件中的部分並以適當的方式
/etc/my.cnf
寫入。這是我的做法:unit``/etc/systemd/system
/etc/my.cnf 文件的配置:
[mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin [mysqld1] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port=3306 datadir=/var/lib/mysql server_id=1 log-bin=mysql-bin binlog_format=mixed [mysqld2] user = mysql pid-file = /var/run/mysqld/mysqld2.pid socket = /var/run/mysqld/mysqld2.sock port=3307 datadir=/var/lib/mysql2 server_id=2 skip-log-bin [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
/etc/systemd/system/mysqld_multi_service.service的配置:
[Unit] Description= mysqld_multi_service [Service] Type=simple ExecStart=/usr/bin/mysqld_multi start ExecStop=/usr/bin/mysqld_multi stop RemainAfterExit=yes [Install] WantedBy=multi-user.target
然後
systemctl enable mysqld_multi_service.service
和systemctl start mysqld_multi_service.service
。在所有這些步驟之後,您可以使用以下命令連接到第一個實例:
mysql -u root -S /var/run/mysqld/mysqld.sock
或第二種情況:
mysql -u root -S /var/run/mysqld/mysqld2.sock