使用 Travis CI 配置 Mysql 5.7

Configure Mysql 5.7 with Travis CI

我无法 运行 在 Travis CI 上进行测试,因为我找不到在容器中设置 mysql 5.7 的方法。

我发现这个要点 https://gist.github.com/BenMorel/d981f25ead0926a0cb6d 解释了 travis.yml 的配置方法。以下是命令:

sudo apt-get remove --purge "^mysql.*"
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql
sudo rm -rf /var/log/mysql
echo mysql-apt-config mysql-apt-config/enable-repo select mysql-5.7-dmr | sudo debconf-set-selections
wget http://dev.mysql.com/get/mysql-apt-config_0.2.1-1ubuntu12.04_all.deb
sudo dpkg --install mysql-apt-config_0.2.1-1ubuntu12.04_all.deb
sudo apt-get update -q
sudo apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" mysql-server

在那之后,我正在做:

$ mysql -uroot < tests/ApiBundle/Datas/dump_test.sql
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

为什么??我已经尝试了很多东西……Google 绝对不是我在这个问题上的朋友……

好的,我找到了如何在 Travis CI 默认容器中重新安装 MySQL 5.6。

这是 .travis.yml 中需要的内容:

services:
  - mysql
sudo: true
before_script:
  - bash .travis.install-mysql-5.7.sh

这里是 .travis.install-mysql-5.7.sh(感谢@codyzu 回答编辑):

echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections
wget https://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg --install mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update -q
sudo apt-get install -q -y --allow-unauthenticated -o Dpkg::Options::=--force-confnew mysql-server
sudo mysql_upgrade

希望对遇到同样问题的人有所帮助!

根据当前文档,您只需要启用 sudo,并在您的 .travis.yml 文件中添加以下配置

addons:
  apt:
   sources:
    - mysql-5.7-trusty
   packages:
    - mysql-server
    - mysql-client

来源https://docs.travis-ci.com/user/database-setup/#MySQL-5.7