mysql / mariadb : create db, user and grant oneliner

CREATE DATABASE dbname CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER dbuser@localhost identified by 'pwd'; GRANT ALL PRIVILEGES on dbname.* to dbuser@localhost; FLUSH privileges;

 

Restore a Single MySQL Database from a Full MySQL Dump

If you backed up all your databases using the -all-databases option and you want to restore a single database from a backup file which contains multiple databases use the --one-database option as shown below:

mysql --one-database database_name < all_databases.sql

Export and Import a MySQL Database in One Command

Instead of creating a dump file from one database and then import the backup into another MySQL database you can use the following one-liner:

mysqldump -u root -p database_name | mysql -h remote_host -u root -p remote_database_name

The command above will pipe the output to a mysql client on the remote host and it will import it into a database named remote_database_name. Before running the command, make sure the database already exists on the remote server