MySQL Commands Cheat Sheet
This cheat sheet provides essential MySQL commands for developers to efficiently manage their databases. It covers common tasks such as connecting to a MySQL server, backing up databases, and restoring them from backups.
MySQL Connection Commands
Learn how to establish a connection to your MySQL server using various methods.
Command | Description |
---|---|
mysql -u root -p |
Connect to MySQL as the root user. You will be prompted for the password. |
mysql -u <user> -p |
Connect to MySQL as a specific user. Replace <user> with the desired username. |
mysql -u root -p -h <host> |
Connect to MySQL on a specific host. Replace <host> with the IP address or hostname of the MySQL server. |
MySQL Backup and Restore Commands
Master the art of safeguarding your data with these crucial backup and restore commands.
Command | Description |
---|---|
mysqldump -u root -p <database> > backup.sql |
Backup a specific database to a file named backup.sql . Replace <database> with the name of the database you want to back up. |
mysql -u root -p <database> < backup.sql |
Restore a database from a backup file. Replace <database> with the name of the database you want to restore to, and backup.sql with the path to your backup file. |