Avatar billede tarj1974 Nybegynder
26. april 2011 - 19:04 Der er 8 kommentarer

Opretelse af MySQL databaser og brugere af disse

Jeg får følgende fejl
+ mysql -uroot -p""dummy""
ERROR at line 1: Unknown command '\''.

ved

mysql -uroot -p${ROOTPASSWD} << EOT
create user \'$USRNME\' identified by \'${DBPASSWD}\';
grant all privileges on \'$UNDERSCORENAME\'.* to \'$USRNME\'@\'localhost\';
exit;
EOT

og længre nede

+ mysqladmin create test_tj_Juac_dk -utj -pu1PDgtO7Cw/kQ
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'tj'@'localhost' (using password: YES)'

ved

DBPASSWD_TMP=`cat "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt"`
echo "${DBPASSWD_TMP}"
mysqladmin create ${UNDERSCORENAME} -u${USRNME} -p${DBPASSWD_TMP}

Hjælp ønskes :)

Thomas :)
Avatar billede jakobdo Ekspert
26. april 2011 - 21:11 #1
Skal det ikke være mellemrum mellem:
-u root og -p PASSWORD ?
Avatar billede tarj1974 Nybegynder
27. april 2011 - 09:53 #2
Det tror jeg ikke. hvis jeg adskiller -p og password tror den at password er en kommando.

Thomas :)
Avatar billede jakobdo Ekspert
27. april 2011 - 10:03 #3
Forstår jeg dog ikke.
se her:

http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html

--user=user_name
eller
-u user_name

og

--password[=password]
eller
-p[password]

udelades password, bør den prompte for det.
Avatar billede tarj1974 Nybegynder
27. april 2011 - 11:18 #4
1. Koden
2. outputet

1.


#!/bin/bash
set -x
#
ROOTPASSWD='""kodeord""'
MNDOMN='juac.dk'
MNDOMNUNDERSCORE='Juac_dk'
IP=90.184.106.85
#
#for USRNME in /home/*
USRARRAY=$(ls -l --format=single-column /home/)
for USRNME in ${USRARRAY[@]}
do
DIR="/home/${USRNME}/PUBLIC_HTML"
if [ ! -d ${DIR} ];
then
  mkdir ${DIR}
fi
if [ ! -e /home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt ];
then
DBPASSWD=`mkpasswd qwerty`
echo "${DBPASSWD}"
mysql -u root -p[${ROOTPASSWD}] << EOT
create user \'$USRNME\' identified by \'${DBPASSWD}\';
grant all privileges on \'$UNDERSCORENAME\'.* to \'$USRNME\'@\'localhost\';
exit;
EOT
echo "The username of the databases is ${USRNME}. And the password for the databases is ${DBPASSWD}" > "/home/${USRNME}/PUBLIC_HTML/your_databases.txt"
echo ${DBPASSWD} > "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt"
fi
#for USRDOMN in /home/${USRNME}/PUBLIC_HTML/*
USRDOMNARRAY=$(ls -l --format=single-column /home/${USRNME}/PUBLIC_HTML/)
for USRDOMN in ${USRDOMNARRAY[@]}
do
  LNK=${USRDOMN}.${USRNME}.${MNDOMN}
  UNDERSCORENAME=${USRDOMN}_${USRNME}_${MNDOMNUNDERSCORE}
  echo "USRDOMN:"${USRDOMN}
  echo "USRNME:"${USRNME}
  if [ ! -e /home/${USRNME}/PUBLIC_HTML/${USRDOMN}.reserved -a -d /home/${USRNME}/PUBLIC_HTML/${USRDOMN} ];
  then
  mkdir "/usr/lib/cgi-bin/${UNDERSCORENAME}"
  echo "<VirtualHost *:80>
ServerAdmin ${USRNME}@${MNDOMN}
ServerName www.${LNK}
ServerAlias ${LNK}
DocumentRoot ${DIR}/${USRDOMN}
  # Set Document Root directory options
  <Directory />
    Options FollowSymlinks -Indexes Includes
    # Allow use of .htaccess file
    AllowOverride Limit FileInfo
  </Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/${UNDERSCORENAME}
  # Set CGI-BIN directory options
  <Directory /cgi-bin>
    AllowOverride None
    Options +ExecCGI -Multiviews +SymlinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>" > "/etc/apache2/sites-available/${UNDERSCORENAME}"
  /usr/sbin/a2ensite ${UNDERSCORENAME}
  echo "${IP} WWW.${LNK} ${LNK}" >> /etc/hosts
  #/etc/init.d/apache2 stop
  #/etc/init.d/apache2 start
  #/usr/sbin/apache2ctl configtest &&
  #/usr/sbin/apache2ctl graceful
  /etc/init.d/apache2 reload
  #echo "${DBPASSWD}"
  DBPASSWD_TMP=`cat "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt"`
  echo "${DBPASSWD_TMP}"
  mysqladmin create ${UNDERSCORENAME} -u ${USRNME} -p[${DBPASSWD_TMP}]
  touch /home/${USRNME}/PUBLIC_HTML/${USRDOMN}.reserved
chown -R www-data:${USRNME} /home/${USRNME}/PUBLIC_HTML/
find /home/${USRNME}/PUBLIC_HTML/ -type f | xargs chmod -R 0644
find /home/${USRNME}/PUBLIC_HTML/ -type d | xargs chmod -R 0755
  fi
done
done



2.

debian:/media/disk# ./addsubdomain40
+ ROOTPASSWD=kodeord
+ MNDOMN=juac.dk
+ MNDOMNUNDERSCORE=Juac_dk
+ IP=90.184.106.85
++ ls -l --format=single-column /home/
+ USRARRAY=tj
+ for USRNME in '${USRARRAY[@]}'
+ DIR=/home/tj/PUBLIC_HTML
+ '[' '!' -d /home/tj/PUBLIC_HTML ']'
+ '[' '!' -e /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt ']'
++ mkpasswd qwerty
+ DBPASSWD=rQ67Sep2sMA9I
+ echo rQ67Sep2sMA9I
rQ67Sep2sMA9I
+ mysql -u root '-p[kodeord]'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
+ echo 'The username of the databases is tj. And the password for the databases is rQ67Sep2sMA9I'
+ echo rQ67Sep2sMA9I
++ ls -l --format=single-column /home/tj/PUBLIC_HTML/
+ USRDOMNARRAY='DB_USER_PASSWD.txt
tester
your_databases.txt'
+ for USRDOMN in '${USRDOMNARRAY[@]}'
+ LNK=DB_USER_PASSWD.txt.tj.juac.dk
+ UNDERSCORENAME=DB_USER_PASSWD.txt_tj_Juac_dk
+ echo USRDOMN:DB_USER_PASSWD.txt
USRDOMN:DB_USER_PASSWD.txt
+ echo USRNME:tj
USRNME:tj
+ '[' '!' -e /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt.reserved -a -d /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt ']'
+ for USRDOMN in '${USRDOMNARRAY[@]}'
+ LNK=tester.tj.juac.dk
+ UNDERSCORENAME=tester_tj_Juac_dk
+ echo USRDOMN:tester
USRDOMN:tester
+ echo USRNME:tj
USRNME:tj
+ '[' '!' -e /home/tj/PUBLIC_HTML/tester.reserved -a -d /home/tj/PUBLIC_HTML/tester ']'
+ mkdir /usr/lib/cgi-bin/tester_tj_Juac_dk
+ echo '<VirtualHost *:80>
ServerAdmin tj@juac.dk
ServerName www.tester.tj.juac.dk
ServerAlias tester.tj.juac.dk
DocumentRoot /home/tj/PUBLIC_HTML/tester
  # Set Document Root directory options
  <Directory />
    Options FollowSymlinks -Indexes Includes
    # Allow use of .htaccess file
    AllowOverride Limit FileInfo
  </Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/tester_tj_Juac_dk
  # Set CGI-BIN directory options
  <Directory /cgi-bin>
    AllowOverride None
    Options +ExecCGI -Multiviews +SymlinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>'
+ /usr/sbin/a2ensite tester_tj_Juac_dk
Enabling site tester_tj_Juac_dk.
Run '/etc/init.d/apache2 reload' to activate new configuration!
+ echo '90.184.106.85 www.tester.tj.juac.dk tester.tj.juac.dk'
+ /etc/init.d/apache2 reload
Reloading web server config: apache2.
++ cat /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt
+ DBPASSWD_TMP=rQ67Sep2sMA9I
+ echo rQ67Sep2sMA9I
rQ67Sep2sMA9I
+ mysqladmin create tester_tj_Juac_dk -u tj '-p[rQ67Sep2sMA9I]'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'tj'@'localhost' (using password: YES)'
+ touch /home/tj/PUBLIC_HTML/tester.reserved
+ chown -R www-data:tj /home/tj/PUBLIC_HTML/
+ find /home/tj/PUBLIC_HTML/ -type f
+ xargs chmod -R 0644
+ find /home/tj/PUBLIC_HTML/ -type d
+ xargs chmod -R 0755
+ for USRDOMN in '${USRDOMNARRAY[@]}'
+ LNK=your_databases.txt.tj.juac.dk
+ UNDERSCORENAME=your_databases.txt_tj_Juac_dk
+ echo USRDOMN:your_databases.txt
USRDOMN:your_databases.txt
+ echo USRNME:tj
USRNME:tj
+ '[' '!' -e /home/tj/PUBLIC_HTML/your_databases.txt.reserved -a -d /home/tj/PUBLIC_HTML/your_databases.txt ']'
debian:/media/disk#
Avatar billede jakobdo Ekspert
27. april 2011 - 11:26 #5
Du skal ikke have [ ] omkring kodeordet...
Avatar billede tarj1974 Nybegynder
27. april 2011 - 11:54 #6
geninstallerer lige debian på en virtual machine
Avatar billede tarj1974 Nybegynder
27. april 2011 - 12:22 #7
Skal ud i byen. kommer tilbage senere
Avatar billede tarj1974 Nybegynder
27. april 2011 - 19:12 #8
igen med få ændringer:

1. koden

2. ouputet

1. #!/bin/bash
set -x
#
ROOTPASSWD='kode'
MNDOMN='juac.dk'
MNDOMNUNDERSCORE='Juac_dk'
IP=90.184.106.85
#
#for USRNME in /home/*
USRARRAY=$(ls -l --format=single-column /home/)
for USRNME in ${USRARRAY[@]}
do
DIR="/home/${USRNME}/PUBLIC_HTML"
if [ ! -d ${DIR} ];
then
  mkdir ${DIR}
fi
if [ ! -e /home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt ];
then
DBPASSWD=`mkpasswd qwerty`
echo "${DBPASSWD}"
mysql --user=root --password=${ROOTPASSWD} << EOT
create user \'$USRNME\' identified by \'${DBPASSWD}\';
grant all privileges on \'$UNDERSCORENAME\'.* to \'$USRNME\'@\'localhost\';
exit;
EOT
echo "The username of the databases is ${USRNME}. And the password for the databases is ${DBPASSWD}" > "/home/${USRNME}/PUBLIC_HTML/your_databases.txt"
echo ${DBPASSWD} > "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt"
fi
#for USRDOMN in /home/${USRNME}/PUBLIC_HTML/*
USRDOMNARRAY=$(ls -l --format=single-column /home/${USRNME}/PUBLIC_HTML/)
for USRDOMN in ${USRDOMNARRAY[@]}
do
  LNK=${USRDOMN}.${USRNME}.${MNDOMN}
  UNDERSCORENAME=${USRDOMN}_${USRNME}_${MNDOMNUNDERSCORE}
  echo "USRDOMN:"${USRDOMN}
  echo "USRNME:"${USRNME}
  if [ ! -e /home/${USRNME}/PUBLIC_HTML/${USRDOMN}.reserved -a -d /home/${USRNME}/PUBLIC_HTML/${USRDOMN} ];
  then
  mkdir "/usr/lib/cgi-bin/${UNDERSCORENAME}"
  echo "<VirtualHost *:80>
ServerAdmin ${USRNME}@${MNDOMN}
ServerName www.${LNK}
ServerAlias ${LNK}
DocumentRoot ${DIR}/${USRDOMN}
  # Set Document Root directory options
  <Directory />
    Options FollowSymlinks -Indexes Includes
    # Allow use of .htaccess file
    AllowOverride Limit FileInfo
  </Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/${UNDERSCORENAME}
  # Set CGI-BIN directory options
  <Directory /cgi-bin>
    AllowOverride None
    Options +ExecCGI -Multiviews +SymlinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>" > "/etc/apache2/sites-available/${UNDERSCORENAME}"
  /usr/sbin/a2ensite ${UNDERSCORENAME}
  echo "${IP} WWW.${LNK} ${LNK}" >> /etc/hosts
  #/etc/init.d/apache2 stop
  #/etc/init.d/apache2 start
  #/usr/sbin/apache2ctl configtest &&
  #/usr/sbin/apache2ctl graceful
  /etc/init.d/apache2 reload
  #echo "${DBPASSWD}"
  DBPASSWD_TMP=`cat "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt"`
  echo "${DBPASSWD_TMP}"
  mysqladmin create ${UNDERSCORENAME} --user=${USRNME} --password=${DBPASSWD_TMP}
  touch /home/${USRNME}/PUBLIC_HTML/${USRDOMN}.reserved
chown -R www-data:${USRNME} /home/${USRNME}/PUBLIC_HTML/
find /home/${USRNME}/PUBLIC_HTML/ -type f | xargs chmod 0644
find /home/${USRNME}/PUBLIC_HTML/ -type d | xargs chmod 0755
  fi
done
done

2.

root@debian:/media/d644e576-b072-47d8-8f77-7b11448079b1# ./addsubdomain42
+ ROOTPASSWD=kode
+ MNDOMN=juac.dk
+ MNDOMNUNDERSCORE=Juac_dk
+ IP=90.184.106.85
++ ls -l --format=single-column /home/
+ USRARRAY=tj
+ for USRNME in '${USRARRAY[@]}'
+ DIR=/home/tj/PUBLIC_HTML
+ '[' '!' -d /home/tj/PUBLIC_HTML ']'
+ '[' '!' -e /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt ']'
++ mkpasswd qwerty
+ DBPASSWD=pgeOj8R/HSfE.
+ echo pgeOj8R/HSfE.
pgeOj8R/HSfE.
+ mysql --user=root --password=kode
ERROR at line 1: Unknown command '\''.
+ echo 'The username of the databases is tj. And the password for the databases is pgeOj8R/HSfE.'
+ echo pgeOj8R/HSfE.
++ ls -l --format=single-column /home/tj/PUBLIC_HTML/
+ USRDOMNARRAY='DB_USER_PASSWD.txt
test
your_databases.txt'
+ for USRDOMN in '${USRDOMNARRAY[@]}'
+ LNK=DB_USER_PASSWD.txt.tj.juac.dk
+ UNDERSCORENAME=DB_USER_PASSWD.txt_tj_Juac_dk
+ echo USRDOMN:DB_USER_PASSWD.txt
USRDOMN:DB_USER_PASSWD.txt
+ echo USRNME:tj
USRNME:tj
+ '[' '!' -e /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt.reserved -a -d /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt ']'
+ for USRDOMN in '${USRDOMNARRAY[@]}'
+ LNK=test.tj.juac.dk
+ UNDERSCORENAME=test_tj_Juac_dk
+ echo USRDOMN:test
USRDOMN:test
+ echo USRNME:tj
USRNME:tj
+ '[' '!' -e /home/tj/PUBLIC_HTML/test.reserved -a -d /home/tj/PUBLIC_HTML/test ']'
+ mkdir /usr/lib/cgi-bin/test_tj_Juac_dk
+ echo '<VirtualHost *:80>
ServerAdmin tj@juac.dk
ServerName www.test.tj.juac.dk
ServerAlias test.tj.juac.dk
DocumentRoot /home/tj/PUBLIC_HTML/test
  # Set Document Root directory options
  <Directory />
    Options FollowSymlinks -Indexes Includes
    # Allow use of .htaccess file
    AllowOverride Limit FileInfo
  </Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/test_tj_Juac_dk
  # Set CGI-BIN directory options
  <Directory /cgi-bin>
    AllowOverride None
    Options +ExecCGI -Multiviews +SymlinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>'
+ /usr/sbin/a2ensite test_tj_Juac_dk
Enabling site test_tj_Juac_dk.
Run '/etc/init.d/apache2 reload' to activate new configuration!
+ echo '90.184.106.85 www.test.tj.juac.dk test.tj.juac.dk'
+ /etc/init.d/apache2 reload
Reloading web server config: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
.
++ cat /home/tj/PUBLIC_HTML/DB_USER_PASSWD.txt
+ DBPASSWD_TMP=pgeOj8R/HSfE.
+ echo pgeOj8R/HSfE.
pgeOj8R/HSfE.
+ mysqladmin create test_tj_Juac_dk --user=tj --password=pgeOj8R/HSfE.
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'tj'@'localhost' (using password: YES)'
+ touch /home/tj/PUBLIC_HTML/test.reserved
+ chown -R www-data:tj /home/tj/PUBLIC_HTML/
+ find /home/tj/PUBLIC_HTML/ -type f
+ xargs chmod 0644
+ find /home/tj/PUBLIC_HTML/ -type d
+ xargs chmod 0755
+ for USRDOMN in '${USRDOMNARRAY[@]}'
+ LNK=your_databases.txt.tj.juac.dk
+ UNDERSCORENAME=your_databases.txt_tj_Juac_dk
+ echo USRDOMN:your_databases.txt
USRDOMN:your_databases.txt
+ echo USRNME:tj
USRNME:tj
+ '[' '!' -e /home/tj/PUBLIC_HTML/your_databases.txt.reserved -a -d /home/tj/PUBLIC_HTML/your_databases.txt ']'

root@debian:/media/d644e576-b072-47d8-8f77-7b11448079b1# hostname localhost
root@debian:/media/d644e576-b072-47d8-8f77-7b11448079b1#
root@debian:/media/d644e576-b072-47d8-8f77-7b11448079b1#
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester