MySQL Forums
Forum List  »  Newbie

Re: mysqldump restore
Posted by: Barry Galbraith
Date: January 22, 2024 04:57AM

mysql is a commandline client program used to interact with mysql RDBMS.

See the refman for how to use mysql cli

mysql cli can be used interactively, enter sql, and get the results, enter more sql etc etc


you can have mysql execute "something" and quit.

The syntax shown in the refman

mysql db_name < script.sql >
invokes mysql, tells it to read input from a file script.sql and output the result to file
That said, you will need some way to provide user and password to mysql, probably in my.cnf (or my.ini) file.

You have the alternative of putting the sql you want executed on the commandline with option -e

Your attempt

mysql -u$user -p$password CREATE DATABASE $db_name;
looks like a mix of the two, being executed in a script (php?)
Perhaps something like this is more to your liking.
mysql -u$user -p$password -e"CREATE DATABASE $db_name";
Untested code.
Or, put your sql in a file, and have mysql read from that file.

Good luck,

Options: ReplyQuote

Written By
January 19, 2024 11:45AM
Re: mysqldump restore
January 22, 2024 04:57AM

Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.