如何将 MariaDB 的 mysqld 与 MySQL 8 的 mysqld 进程分开来解决 A mysqld 进程已存在错误?

如何将 MariaDB 的 mysqld 与 MySQL 8 的 mysqld 进程分开来解决 A mysqld 进程已存在错误?

我的目标是在同一台 Ubuntu 18.04 服务器上安装 MariaDB 10.1 和 MySQL 8。

我能够成功设置 MySQL 8,但在按照本指南设置 MariaDB 时几乎在最后陷入困境:

https://mariadb.com/kb/en/library/installing-mariadb-alongside-mysql/

基本上这就是我所做的:

  1. 下载 Linux 版 mariadb
  2. 将提取的文件夹复制到 /opt/mariadb
  3. 创建 /opt/mariadb-data 文件夹
  4. 由 mariadb 用户 chown'ed(新创建)
  5. 将 my.cnf 复制到 /opt/mariadb-data 并编辑端口号和用户、basedir 和 datadir。将 mysql.service 文件复制到 /etc/init.d/mariadb 并对其进行编辑
  6. 运行安装脚本
  7. 尝试启动,并收到此错误:
Warning: The unit file, source configuration file or drop-ins of mariadb.service changed on disk. Run 'systemctl daemon-reload' to reload
● mariadb.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/init.d/mariadb; generated)
   Active: failed (Result: exit-code) since Thu 2019-08-29 23:27:12 EDT; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 35976 ExecStop=/etc/init.d/mariadb stop (code=exited, status=0/SUCCESS)
  Process: 36610 ExecStart=/etc/init.d/mariadb start (code=exited, status=1/FAILURE)
    Tasks: 28 (limit: 4563)
   CGroup: /system.slice/mariadb.service
           ├─33699 /bin/sh /opt/mariadb/bin/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir=/opt/mariadb/data --pid-file=/o
           └─33830 /opt/mariadb/bin/mysqld --defaults-file=/opt/mariadb-data/my.cnf --basedir=/opt/mariadb --datadir=/opt/mariadb/data --p

Aug 29 23:27:11 dev03.example.com systemd[1]: Starting LSB: start and stop MySQL...
Aug 29 23:27:11 dev03.example.com mariadb[36610]: Starting MySQL
Aug 29 23:27:11 dev03.example.com mariadb[36610]: .190829 23:27:11 mysqld_safe Logging to '/opt/mariadb-data/dev03.example.com.err'.
Aug 29 23:27:11 dev03.example.com mariadb[36610]: 190829 23:27:11 mysqld_safe A mysqld process already exists
Aug 29 23:27:12 dev03.example.com mariadb[36610]:  *
Aug 29 23:27:12 dev03.example.com systemd[1]: mariadb.service: Control process exited, code=exited status=1
Aug 29 23:27:12 dev03.example.com systemd[1]: mariadb.service: Failed with result 'exit-code'.
Aug 29 23:27:12 dev03.example.com systemd[1]: Failed to start LSB: start and stop MySQL.


这是我按照教程链接为 my.cnf 设置的配置的重要部分。

Create a new my.cnf in /opt/mariadb from support files:
[root@mariadb-near-mysql opt]# cp mariadb/support-files/my-medium.cnf mariadb-data/my.cnf
[root@mariadb-near-mysql opt]# chown mariadb:mariadb mariadb-data/my.cnf
Edit the file /opt/mariadb-data/my.cnf and add custom paths, socket, port, user and the most important of all: data directory and base directory. Finally the file should have at least the following:
[client]
port        = 3307
socket      = /opt/mariadb-data/mariadb.sock

[mysqld]
datadir         = /opt/mariadb-data
basedir         = /opt/mariadb
port        = 3307
socket      = /opt/mariadb-data/mariadb.sock
user            = mariadb
Copy the init.d script from support files in the right location:
[root@mariadb-near-mysql opt]# cp mariadb/support-files/mysql.server /etc/init.d/mariadb
[root@mariadb-near-mysql opt]# chmod +x /etc/init.d/mariadb
Edit /etc/init.d/mariadb replacing mysql with mariadb as below:
- # Provides: mysql
+ # Provides: mariadb
- basedir=
+ basedir=/opt/mariadb
- datadir=
+ datadir=/opt/mariadb-data
- lock_file_path="$lockdir/mysql"
+ lock_file_path="$lockdir/mariadb"
The trickiest part will be the last changes to this file. You need to tell mariadb to use only one cnf file. In the start section after $bindir/mysqld_safe add --defaults-file=/opt/mariadb-data/my.cnf. Finally the lines should look like:

# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
The same change needs to be made to the mysqladmin command below in the wait_for_ready() function so that the mariadb start command can properly listen for the server start. In the wait_for_ready() function, after $bindir/mysqladmin add --defaults-file=/opt/mariadb-data/my.cnf. The lines should look like:

我可以做什么来更改 MariaDB 的 mysqld 进程名称,或者可以通过其他方式避免冲突吗?

相关内容