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.