Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6562335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:41:50+00:00 2026-05-25T13:41:50+00:00

I have a bash that creates a database, assign user rigths to it and

  • 0

I have a bash that creates a database, assign user rigths to it and then load a dump. I do this from a bash in opensuse. A parameter with database name is used = $1.

This is the part of my script that handles this:

echo "creating database"
#(This is Line 22)create new database and configure grants
mysql -hlocalhost -uroot -e "create database $1;"

echo "select db, use"
mysql -hlocalhost -uroot -e "use $1;"

echo "granting rights"
mysql -hlocalhost -uroot -e "grant all on $1.* to 'smic_db_root'@'localhost' identified by 
'sm_for_all_987';"

echo "loading dump"
#load the database dump
mysql -h localhost -uroot $1</opt/otrsadm/otrs_template.sql

And this is from my error log:

 creating database
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 '' at line 1
select db, use
ERROR at line 1: USE must be followed by a database name
granting rights
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 '* to 'smic_db_root'@'localhost' identified by 
'sm_for_all_987'' at line 1
loading dump
ERROR 1046 (3D000) at line 22: No database selected

How do I do in order to chose the database in the bash and when do I need to do it. Since the error message is refering to Line 22, I need to do it somewhere inside. I tried adding the use $1; like this:

mysql -hlocalhost -uroot -e "create database $1; **use $1;** grant all on $1.* to 'smic_db_root'@'localhost' identified by 'sm_for_all_987';"

No difference in behaviour.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:41:50+00:00Added an answer on May 25, 2026 at 1:41 pm

    create/grant commands don’t need a database to be selected. They explicitly work at the global level (create) or on the mysql database (grant). Try putting in some debugging to see eactly where the error(s) occuring?

    echo "creating database"
    mysql .... 'create database ..';
    echo "granting rights"
    mysql .... 'grant ....';
    echo "loading dump"
    mysql .... < file.sql
    

    Right now the error messages do not tell you WHAT failed, just that something did. With the echoes added as above, you’ll at least know which stage caused which error(s).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script that creates a Subversion patch file for the current
I have a bash script that sources contents from another file. The contents of
i have this problem: I have created a bash script that performs some tasks.
I have a .vimrc script that automatically creates a buffer for a bash terminal
I have a bash script that monitors the jobs in a cluster from the
I have a small in-house Python script for Linux that creates a /home/user/environ_script.sh file
I have a bash file that contains wget commands to download over 100,000 files
I have a bash script that runs a simulation program written in Fortran 90,
I have a bash script that does ssh to a remote machine and executes
I have a bash script that cuts out a section of a logfile between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.