MySQL or MariaDB Database Export from Linux CLI - Root @ PuTTy

 Here is how to export database to get a backup copy and restore later.

1) Set a mysql root password

root@system:~# mysqladmin -u root password eDb4bAcKed

Where eDb4bAcKed will be your mysql root password, change it as your desired password.

If you receive any error message about access denied, follow the below command.

root@system:~# sudo mysql

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'eDb4bAcKed';

2) Login to mysql

root@system:~# mysql -u root -p

Enter the mysql root password when prompt

3) List all existing databases

root@host:~# mysql -u root -p

MariaDB [(none)]> SHOW DATABASES;

mysql show databases

And the result will show your system's all databases

mysql listed all databases

When you found the all databases list, note the databases name, and exit from mysql.

4) Export a database to a SQL backup file

[root@system:~#] mysqldump --user=root --password --lock-tables --databases mywebsitedb > /var/www/html/mywebsitedb.sql

And done ! Your exported backup file will be available at /var/www/html/ location.

Post a Comment