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

By | 20 September 2018

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.

Iscriviti al gruppo Telegram Italian Spaghetti Geeks

https://t.me/ItalianSpaghettiGeeks

News e discussioni sulla tecnologia (internet, computer e mobile, telefonia, sat/DTT e streaming, ecc...), giveaways esclusivi prodotti tech, sconti ed offerte e molto altro ancora!

Leave a Reply

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