Laravel Homestead:安装 MariaDB 0 个改进

修改配置

默认 Homestead 使用的是 MySQL 数据库,如果你想使用 MariaDB 的话,只需要在 Homestead.yaml 中加入 mariadb: true 即可,如下:

Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

# 使用 MariaDB 而非 MySQL
mariadb:  true

.
.
.

应用修改

保存修改后在主机中使用以下命令应用修改到 Homestead 虚拟机中:

> vagrant reload --provision

连接信息

MariaDB 的连接信息与 MySQL 一致。

虚拟机

  • host: 127.0.0.1
  • user: homestead
  • pass: secret
  • port: 3306

主机

  • host: 192.168.10.10
  • user: homestead
  • pass: secret
  • port: 33060

背后的代码

这里我们简单讲下以上操作背后的信息,以助于理解其工作原理。

当配置信息里设置了 mariadb: true 时,会触发 homestead.rb 里的这段操作 ,然后会去调用 Shell 脚本 install-maria.sh 来安装 MariaDB 数据库。

另外需要注意的是,安装 MariaDB 的话 MySQL 将会被移除,就如 install-maria.sh 所示:

# 移除 MySQL

apt-get remove -y --purge mysql-server mysql-client mysql-common
apt-get autoremove -y
apt-get autoclean

rm -rf /var/lib/mysql
rm -rf /var/log/mysql
rm -rf /etc/mysql
本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 1
longren610

求助,安装mariadb一直无法成功,总是报一堆错误。有人成功安装过mariadb么?

    homestead: Preparing to unpack .../00-mariadb-server-10.5_1%3a10.5.5+maria~focal_amd64.deb ...
    homestead: /var/lib/mysql: found previous version 8.0
    homestead: The file /var/lib/mysql/debian-8.0.flag indicates a
    homestead: version that cannot automatically be upgraded. Therefore the
    homestead: previous data directory will be renamed to /var/lib/mysql-8.0 and
    homestead: a new data directory will be initialized at /var/lib/mysql.
    homestead: Please manually export/import your data (e.g. with mysqldump) if needed.
    homestead: mv: cannot stat '/etc/mysql/debian.cnf': No such file or directory
.....
    homestead: Errors were encountered while processing:
    homestead:  /tmp/apt-dpkg-install-OfE1Kl/00-mariadb-server-10.5_1%3a10.5.5+maria~focal_amd64.deb
    homestead: E
    homestead: :
    homestead: Sub-process /usr/bin/dpkg returned an error code (1)
    homestead: sed: can't read /etc/mysql/mariadb.conf.d/50-server.cnf: No such file or directory
    homestead: ERROR
    homestead:  2002 (HY000)
    homestead: : Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    homestead: Failed to restart mysql.service: Unit mysql.service not found.
    homestead: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    homestead: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    homestead: ERROR
    homestead:  2002 (HY000)
    homestead: : Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    homestead: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    homestead: Failed to restart mysql.service: Unit mysql.service not found.
    homestead: Looking for 'mysql' as: mysql
    homestead: Looking for 'mysqlcheck' as: mysqlcheck
    homestead: Version check failed. Got the following error when calling the 'mysql' command line client
    homestead: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    homestead: FATAL ERROR: Upgrade failed
    homestead: Failed to restart mysql.service: Unit mysql.service not found.
==> homestead: Running provisioner: Creating MySQL Database: homestead (shell)...
    homestead: Running: script: Creating MySQL Database: homestead
    homestead: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
6个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!