How to use MySql database in travis CI

language: python
sudo: enabled
services:
    - mysql
python:
    - "3.7.3"
env:
    global:
     - TRAVIS=true
before_install:
    - sudo mysql -e 'CREATE DATABASE pianyuan;'
    - sudo mysql -e 'select database();'
    - sudo mysql -e 'SHOW DATABASES;'
    - sudo mysql -e 'USE pianyuan;'
    - sudo mysql -e 'select database();'
    - sudo mysql --version
# command to install dependencies
install:
    - pip install -r requirements.txt
script:
    - python main.py

but the code - sudo mysql -e 'USE pianyuan;' didn’t worked, I couldn’t select a mysql database, WHY???

Would it be possible for you to post the name of your repository and a link/url to a build that shows the error you mention? Thanks!

In this commit, I create a database, but the cli use pianyuan didn’t work, I could’t not create a table because CI told me that No database selected

In this github commit

Every

sudo mysql -e ...

is separate process. Once completed its effect on connection is gone.

Try

sudo mysql -e 'USE pianyuan; create  table film...;'
1 Like

thanks, It’s work!