LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 02-19-2010, 09:20 PM   #1
wegadnie
Member
 
Registered: Oct 2007
Posts: 48

Rep: Reputation: 15
MySQL - Script to create account


Hi,

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:

Code:
!/bin/bash
# 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
out=execute

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

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
  done
  mysql -u root --password="somepass" -e "`cat /execute`"
fi
When i execute the script, i got error related to the MySQL syntax.

Quote:
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, 06:09 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697

Rep: Reputation: 93
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, 08:02 AM   #3
Blue_Ice
Member
 
Registered: Jul 2006
Location: Belgium
Distribution: Debian, Fedora, CentOS, Windows
Posts: 352

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:
Code:
CREATE DATABASE IF NOT EXISTS userdb;
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.

Arjan
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 10:45 PM.

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