Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 02-19-2010, 10:20 PM   #1
Registered: Oct 2007
Posts: 48

Rep: Reputation: 15
MySQL - Script to create account


I use a script to create user's database. The user's account is got from a csv file. This is the script i use to create the account for user that is pulled out from the csv file:

# Description
# Change ownership for each user from  CSV file, grant permissions
# CSV File Format
# Each user id is in 1 line
# Description End

export PATH=$PATH:/usr/sbin

#Check argument
if [ -z $1 ]; then
  echo "Usage: `basename $0` <csv file>"
  exit 1

test -f $out && rm -f $out

if [ -r $1 ]; then
  cat $1 |
  while read line; do
    userid=$(echo $line | cut -f1 -d\n)  
    echo "create database $userid;" >> $out
    echo "GRANT ALL ON $userid.* To $userid IDENTIFIED BY \"somepass\";" >> $out
  mysql -u root --password="somepass" -e "`cat /execute`"
When i execute the script, i got error related to the MySQL syntax.

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 'Acou' at line 1
Can someone here help me to give the right syntax to call the database to create database for users?
Old 02-20-2010, 07:09 AM   #2
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
It looks like you're building a script and then trying to run the script.

My suggestion would be to name the script with the traditional .sql
extension. This means the file that is referred to as execute and
/execute would become execute.sql. You would run it like this:
mysql -u root -p"somepass" < execute.sql

Try doing this and then posting the first line of the execute.sql file.
Old 02-22-2010, 09:02 AM   #3
Registered: Jul 2006
Location: Belgium
Distribution: Debian, Fedora, CentOS, Windows
Posts: 361

Rep: Reputation: Disabled
What is the content of the file 'execute'?
I think that you are missing some quotes in your SQL statement.

It should look like this:
CREATE USER 'userid'@'%' IDENTIFIED BY 'some_password';
GRANT ALL ON userdb.* TO 'userid'@'%';
Be aware that I used userdb as the database name and userid for the username. In your case this would be the same. What is important and also the reason why I made this distinction, is when you use userid you need to put single quotes around it. This is not permitted when using the database name. The %-sign is to tell the server that access is allowed from any client.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create new user account rachala2 Linux - Newbie 2 01-04-2009 02:29 AM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 11:13 AM
How can I create a mail account? Md.Abul Quashem Linux - Server 3 11-14-2008 09:01 AM
how to create a root account avimd Ubuntu 5 10-09-2005 09:10 AM
Create FTP account Swakoo Linux - Newbie 1 06-13-2005 07:16 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration