Submitted by hashim on Fri, 25/03/2005 - 23:22.
( categories: Programming )

Al salamo alikom

i want to make a database installation for mysql i have the SQL file and mysqluser, mysqlpass

if i will make it manually i will make mysql -uuser -ppass source = path

how i can make it as script file? when i make the first line mysql ... it will wait till this command ends

i want to make one shell script to login to mysql, and execute the sql file thank you.


Pronco's picture
Submitted by Pronco on Sat, 26/03/2005 - 04:30.

If you want the script to not wait for mysql to end, put the "&" character at the end of the line. That will cause the process to be run in the background.

mysql &

then it doesent wait


I used to be indecisive .. but now I'm not so sure


Conceptor's picture
Submitted by Conceptor on Sat, 26/03/2005 - 05:27.

the ampersand sign "&" will make backgrounding for the process .and i think mysql is a shell-like that should be presented to type your commands(queries or what ever).

I did not get the question .but if he means that he want to supply the user name , password and the source path. here is the script

#!/bin/bash
echo "Enter user name"
read user
echo "Enter password"
read passwd
echo "Enter source path"
read srcpath
mysql -u $user -p $passwd source=$srcpath
#i do not think the source thing will work fine

this will take the username and it's pasword and the source path(i do not know what is the source path here but as he supplied on his post.

if he means to apply some create statement or some what ever.

mysql - user -p passwd < myfile.mysql

but this is not script at all.

Diaa Radwan


Pronco's picture
Submitted by Pronco on Sat, 26/03/2005 - 15:01.

You don't need that

mysql installation is generally done redirecting a mysql dump

ie: mysqladmin -d database -u user -p pwd < mysql_dump.sql

so an installation script would just call that command with the dump you provided along with the package


I used to be indecisive .. but now I'm not so sure


Alaa's picture
Submitted by Alaa on Sat, 26/03/2005 - 22:59.

you put your sql code in a file then run


$ mysql -u username -p databasename < foo.sql

note that you end the command with the database name, this will prompt for the password, if you want to put the password on the command line the syntax is


$ mysql -u username -ppassword databasename < foo.sql

incidentally if you want to do the opposit and dump an turn an existing database into an sql script use


$ mysqldump -u username -p databasename > foo.sql

cheers, Alaa


http://www.manalaa.net "i`m feeling for the 2nd time like alice in wonderland reading el wafd"


Submitted by hashim on Sat, 26/03/2005 - 09:33.

mysql - user -p passwd < myfile.mysql i tried this and it worx fine

>mysql - user -p passwd source=myfile.mysql it is not true and i tried it b4

thnx


The wrong make the wrong because it can not find the true to tell him the true.

Ahmed Hashim\

Pronco's picture
Submitted by Pronco on Sat, 26/03/2005 - 15:30.

reading your question it seems you're deploying an app or something that needs to add stuff to mysql. the way to do it is to provide a dump of the tables and the like and use mysqladmin to load it. the manual will tell you more about the syntax

look into any of the app that uses a db as backend for inspiration. they use that method. depending on the level of automation the user is required to run the mysqladmin manually or the script asks him for db root pwd

since you need root pwd to create a new db and grant permissions on it. once you've set it up you can proceed creating a new user for the app and use that

this is the best/secure/widespread approach


I used to be indecisive .. but now I'm not so sure


Submitted by hashim on Sun, 27/03/2005 - 18:30.

Al salamo alikom thank you for your reply, yes, i am deploying the application which uses mysql. i am making this script to dump the database. it is a good idea to look at an application which uses mysql. thnx man


The wrong make the wrong because it can not find the true to tell him the true.

Ahmed Hashim

Michael's picture
Submitted by Michael on Mon, 28/03/2005 - 22:13.

bemonasbet el kalam 3an MySql wel SQL scripts. how can i extract the sql script (schema) for creating a database from an exsiting MySQL database. i mean some thing like this one in the SQLServer Enterprise manager which i can generate the sql script that generates the database back on other servers.

Thank you.


Michael Ageeb
FCI-CU CS Departement
Java! Java! Ja... PHP!!! Why not?


Alaa's picture
Submitted by Alaa on Mon, 28/03/2005 - 23:42.

read my comment above

cheers, Alaa


http://www.manalaa.net "i`m feeling for the 2nd time like alice in wonderland reading el wafd"


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.