提问人:lky 提问时间:7/5/2018 最后编辑:Striezellky 更新时间:1/25/2019 访问量:18056
在Mac上使用MySQL安装MariaDB
Installing MariaDB with MySQL on Mac
问:
我正在尝试使用 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
--------------
答:
同时安装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 up -d
docker-compose.yml
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。
键入用户的密码后,可以发出 SQL 查询:user
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
玩得愉快!
如果你运行 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,都引用相同的数据目录 ,都使用相同的命令,例如 ,所有这些都表明两者可以互换操作。它们不能重合,除非您将它们安装在不同的虚拟机(如 vmware)上或在 docket 容器中运行它们(这在另一个答案中有所建议)。mysql.server start
mysql -h localhost -u root -p
/usr/local/var/mysql
mysqldump
但是,如果您无法在单独的虚拟机或docket容器中运行它们,那么我强烈建议删除MySQL并使用MariaDB,因为MariaDB保持与MySQL的兼容性,但也包含其他功能,例如.CHECK CONSTRAINTS
这就是您删除MySQL并安装MariaDB的方法。请注意,在我的系统中,我通过 HomeBrew 使用 [email protected],所以我指定而不是 mysql:
brew remove [email protected]
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
因此,从安装中可以看出,通过运行,mariadb 已安装在brew info 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
对我来说,由于我已经有一个带有 [email protected] 的数据目录,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。
下一个:溢出滚动不工作IOS
评论
[mysqld]
port=3307