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
https://dev.mysql.com/doc/refman/8.0/en/mysql.html

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

or

you can have mysql execute "something" and quit.

The syntax shown in the refman
Quote

mysql db_name < script.sql > output.tab
invokes mysql, tells it to read input from a file script.sql and output the result to file output.tab
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
https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_execute

Your attempt
Quote

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,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
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.