Skip to Content

MySql DB installation

Ahmed Hashim's picture

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

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

mysql &

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.

then it doesent wait


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

Conceptor's picture

script or create

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

  1. !/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
    1. 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

look into mysqladmin

You don't need that

mysql installation is generally done redirecting a mysql dump

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

databasename not password

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

Alaa


"i`m feeling for the 2nd time like alice in wonderland reading el wafd"

Ahmed Hashim's picture

Done

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

reading your question i

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

Ahmed Hashim's picture

Yes, i am deploying

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

How to regenerat the SQL Script

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.

Alaa's picture

nefata7 showaya

Alaa


"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.


Dr. Radut | forum