我正在尝试使用brew在我的Mac上安装MariaDB。然而,我正在努力安装它,因为它与MySQL冲突。我想知道是否有人可以建议如何设置它,所以我有MariaDB和MySQL,因为我将需要在我的机器上,因为我在多个项目中需要使用一个或另一个。
3x-iMac:~ admin$ mysql.server start
Starting MariaDB
SUCCESS!
3x-iMac:~ admin$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
3x-iMac:~ admin$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> \s
--------------
mysql Ver 15.1 Distrib 10.3.8-MariaDB, for osx10.13 (x86_64) using readline 5.1
Connection id: 24
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MySQL
Server version: 8.0.11 MySQL Community Server - GPL
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 2 hours 47 min 30 sec
Threads: 6 Questions: 1257 Slow queries: 0 Opens: 154 Flush tables: 2 Open tables: 130 Queries per second avg: 0.125
--------------
发布于 2019-01-25 23:12:14
如果您运行brew info,它甚至会警告您不要并排安装它们,因为它们会发生冲突:
brew info mysql
mysql: stable 8.0.13 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
Conflicts with:
mariadb (because mysql, mariadb, and percona install the same binaries.)
mariadb-connector-c (because both install plugins)
mysql-cluster (because mysql, mariadb, and percona install the same binaries.)
mysql-connector-c (because both install MySQL client libraries)
percona-server (because mysql, mariadb, and percona install the same binaries.)
Not installed
实际上,如果运行brew info mariadb
,它会说这是一个Drop-in Replacement
brew info mariadb
mariadb: stable 10.3.12 (bottled)
Drop-in replacement for MySQL
https://mariadb.org/
Conflicts with:
mariadb-connector-c (because both install plugins)
mysql (because mariadb, mysql, and percona install the same binaries.)
mysql-cluster (because mariadb, mysql, and percona install the same binaries.)
mysql-connector-c (because both install MySQL client libraries)
mytop (because both install `mytop` binaries)
percona-server (because mariadb, mysql, and percona install the same binaries.)
/usr/local/Cellar/mariadb/10.3.12 (658 files, 174.4MB) *
Poured from bottle on 2019-01-25 at 09:50:26
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mariadb.rb
==> Dependencies
什么是即插即用的替换?它指的是将一个软件组件替换为另一个软件组件的能力,而不需要任何其他代码或配置更改,并且不会产生任何负面影响。
因此,mysql和mariadb都使用mysql.server start
运行,都使用mysql -h localhost -u root -p
登录mysql,都引用了/usr/local/var/mysql
上的相同数据目录,都使用相同的命令,如mysqldump
,这些都表明两者可以互换操作。它们不可能重合,除非您将它们安装在不同的虚拟机上,如vmware,或者在目录容器中运行它们(这是在另一个答案中建议的)。
但是如果您不能在单独的虚拟机或目录容器中运行它们,那么我强烈建议删除MySQL并使用MariaDB,因为MariaDB保持与MySQL的兼容性,但也包含其他功能,如CHECK CONSTRAINTS
。
这就是删除MySQL并安装MariaDB的方法。注意,在我的系统中,我通过HomeBrew使用mysql@5.7,所以我指定为mysql:
brew remove mysql@5.7
brew cleanup
就是这样。一些指南建议删除单个目录,如下所示:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
但在我的系统上,我的偏好窗格中没有MySQL,也没有启动,甚至没有自动启动。因此,我保存它的唯一位置是/usr/local/var中的实际数据库数据:
/usr/local/var/mysql
但由于MariaDB是一个即用型替代品,因此您不需要删除此数据,MariaDB将在安装后使用它。
因此,要安装MariaDB:
brew install mariadb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/services).
==> New Formulae
...
==> Updated Formulae
...
==> Deleted Formulae
...
==> Downloading https://homebrew.bintray.com/bottles/mariadb-10.3.12.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mariadb-10.3.12.mojave.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
MySQL is configured to only allow connections from localhost by default
To connect:
mysql -uroot
To have launchd start mariadb now and restart at login:
brew services start mariadb
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
/usr/local/Cellar/mariadb/10.3.12: 658 files, 174.4MB
从安装和运行brew info mariadb
中可以看到,mariadb已经安装在
/usr/local/Cellar/mariadb/10.3.12
并且$PATH中的mysql可执行文件指向该MariaDB二进制文件:
$ which mysql
/usr/local/bin/mysql
$ ls -l /usr/local/bin/mysql
lrwxr-xr-x 1 viggy admin 35 Jan 25 09:50 /usr/local/bin/mysql -> ../Cellar/mariadb/10.3.12/bin/mysql
对我来说,因为我已经有了mysql@5.7的数据目录,所以MariaDB可以使用它,我仍然可以访问我的数据(尽管仍然鼓励在删除mysql之前使用mysqldump备份数据库):
mysql -h localhost -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
USE my_old_database;
Database changed
MariaDB [my_old_database]>
如您所见,它现在使用的是MariaDB。
发布于 2018-07-13 04:55:37
同时安装MySQL和MariaDB的问题并不是端口冲突(两个服务器都默认绑定到端口3306 ),因为可以在服务器配置中更改该端口。问题是,MariaDB是MySQL的临时替代品,因此对二进制文件使用相同的路径和名称(例如,mysqld用于服务器,mysql用于客户端)。因此,它们的设计方式是,其中一个安装了一个或另一个,但不是同时安装两个。
更好的方法是为两个数据库服务器设置一个Docker容器并使用它。这种方法还有一个好处,那就是如果需要,还可以运行两个数据库服务器的多个不同版本。不过,您仍然需要将每个容器映射到不同的端口。
设置MySQL 5和MariaDB 10的简单docker-compose.yml
可能如下所示:
version: '2'
services:
mysql5:
image: mysql:5
ports:
- "3305:3306/tcp"
environment:
- MYSQL_ROOT_PASSWORD=secret_password
- MYSQL_USER=user
- MYSQL_PASSWORD=user_password_here
- MYSQL_DATABASE=my_db
mariadb10:
image: mariadb:10
ports:
- "3310:3306/tcp"
environment:
- MYSQL_ROOT_PASSWORD=secret_password
- MYSQL_USER=user
- MYSQL_PASSWORD=user_password_here
- MYSQL_DATABASE=my_db
如果您的系统上已经安装了docker-compose,您可以通过在docker-compose.yml
文件目录中的终端中键入docker-compose up -d
来启动这两个容器。
MySQL 5在端口3305上可用,MariaDB在端口3310上可用。(这样就有可能在端口3306上使用本机MySQL或MariaDB。)当然,数据库用户的环境变量、数据库的密码和名称都应该进行调整。如果您需要不同的版本,MySQL和MariaDB的版本也是如此。
在容器打开(docker-compose up -d
)后,您可以连接到它们,例如通过:
mysql --host=::1 --user=user --password my_db --port=3310
(注意给出正确的端口参数。在本例中,端口3310用于MariaDB 10。)
在输入用户user
的密码之后,您可以发出您的SQL查询:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.5-10.3.8-MariaDB-1:10.3.8+maria~jessie mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| my_db |
+--------------------+
2 rows in set (0,00 sec)
mysql> USE my_db;
Database changed
mysql> SHOW TABLES;
Empty set (0,00 sec)
mysql> quit
Bye
玩得开心!
https://stackoverflow.com/questions/51189634
复制相似问题