travis mysql database create user error

随声附和 提交于 2019-12-04 12:48:26

问题


I wanted to set up travis for my spring-boot project where I use user makler/makler for accessing database. When running travis I get an error saying:

$ mysql -u root -e 'CREATE DATABASE stockmarket;'

$ mysql -u root -e 'CREATE USER 'makler'@'localhost' IDENTIFIED BY 'makler';'
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'makler' at line 1


The command "mysql -u root -e 'CREATE USER 'makler'@'localhost' IDENTIFIED BY 'makler';'" failed and exited with 1 during .

Your build has been stopped.

My travis.yml file looks like:

language: java
jdk:
  - oraclejdk8
services:
  - mysql
dist: trusty
sudo: required
addons:
  apt:
    packages:
    - mysql-server-5.6
    - mysql-client-core-5.6
    - mysql-client-5.6
before_script:
  - mysql -u root -e 'CREATE DATABASE stockmarket;'
  - mysql -u root -e 'CREATE USER 'makler'@'localhost' IDENTIFIED BY 'makler';'
  - mysql -u root -e 'GRANT ALL ON stockmarket.* TO 'makler'@'localhost';'

回答1:


Its the quotes surrounding the query. Update your before_script to surround the queries using double quotes(") instead of single quotes(')

before_script:
- mysql -u root -e 'CREATE DATABASE stockmarket;'
- mysql -u root -e "CREATE USER 'makler'@'localhost' IDENTIFIED BY 'makler';"
- mysql -u root -e "GRANT ALL ON stockmarket.* TO 'makler'@'localhost';"

Build worked fine after I changed it and ran the build on travis. Hope this helps.



来源:https://stackoverflow.com/questions/38955719/travis-mysql-database-create-user-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!