Skip to content
Advertisement

MariaDB : create database and execute sql script without ‘<' character from the command line cmd.exe

I’m trying in every way to create a database and populate it with sql script from the command line.

mysql --user=root --password=hello --execute=create database test --source='accounts.sql'
-> starts to print help

mysql --user=root --password=hello --execute='create database test' --source='accounts.sql'
-> starts to print help

or the only database:

mysql --user=root --password=hello --execute=create database test
ERROR 1049 (42000): Unknown database 'test'

I’m going to manage it through powershell but before to do it I want to be sure it works from mariaDB command line. (Powershell doesn’t recognize ‘<‘ character).

Is it possible create db and populate it from command line ? Thank to all

Advertisement

Answer

The preferrable way to open and populate a database with PowerShell would be to first jump to the mysql command prompt:

    mysql -u {username} -p

Then enter your password. In the mysql CLI, open the database with the following commands:

    use {databasename};
    source {path_to_your_file.sql};

If you have to create the database first, do the following:

    create database {databasename};
    use {databasename};
    source {path_to_your_file.sql};

Or if you prefer oneliners:

   mysql -u{username} -p{password}; create database {databasename}; use {databasename}; source {path_to_your_file.sql};
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement