Create, Delete, Export, Import, Optimize a MySQL database from command line

Reading time: < 1 minute

MySQL

Create, Delete, Export, Import, Optimize a MySQL database are common tasks that can be done with various tools, for example using PHPMyAdmin, a MySQL client, command line.
If you have access to the server you can do these tasks directly from Windows command line or Linux terminal.

Create database

mysql -u [username] -p[password] -e "CREATE DATABASE test CHARACTER SET utf8 COLLATE utf8_general_ci;"

It creates test database with a specific character set and collation, if they aren’t specified will be used the default.

Delete database

mysql -u [username] -p[password] -e "DROP DATABASE test"

Delete the test database.

Export database

mysqldump -u [username] --password=[password] test > dumpdb.sql

Make the dump file called dumpdb.sql of the test database.

Import database

mysql -u [username] --password=[password] -D test < dumpdb.sql"

Import the dumpdb.sql dump file into test database.

Optimize database

mysqlcheck -u [username] --password=[password] -o test

Optimize test database.

Support This Site

If you like what I do please support me on Ko-fi

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Commenti
Oldest
Newest Most Voted
Inline Feedbacks
View all comments