After the successful installation of MySQL on Ubuntu/Linux, you will require specific MySQL command Line instructions to operate the database via the command line or terminal. These commands encompass restarting, stopping, starting, importing, exporting, and optimizing MySQL configuration.
Efficiently Utilizing MySQL Through Command Line on Ubuntu/Linux
Mysql server management commands
Restart command: restart mysql
sudo service mysql restart
Reload command: Reload the configuration and do not reboot
sudo service mysql reload
Stop command: shutdown/stop mysql
sudo service mysql stop
Start command: Launch mysql
sudo service mysql start
The command to enable mysql allows running at system startup
sudo systemctl enable mysql
Disable command: Turn off mysql from system startup
sudo systemctl disable mysql
The update command, updates Mysql on Ubuntu/Linux, this command will update your entire database.
sudo mysql_upgrade
Using MySQL Command Line to Import a Database
Method 1: Importing a Database Using MySQL Command Line or Terminal on Ubuntu/Linux. This method provides visibility into the import process.
sudo mysql (or mysql -u root -p) use: use database; source filedb.sql;
Method 2: Employ the standard MySQL import command through the terminal or command prompt on Linux, Ubuntu, and Windows.
mysql -u username -p database_name < file.sql
Method 3: Unlike Methods 1 and 2, which use MySQL via the command line or terminal, this approach utilizes phpMyAdmin, Adminer, or another web interface for database import. Unlike command-based methods, this allows direct importing through a user-friendly web interface and is suitable for smaller databases.
Uninstall MySQL Completely on Ubuntu and Linux
If you encounter MySQL errors on Ubuntu or decide to switch to another database management system, you can uninstall and completely remove MySQL from Ubuntu and Linux using the terminal commands provided in the following instructions. Please remember to back up your databases before proceeding.
sudo apt purge 'mysql*' sudo apt remove 'mysql*' sudo apt autoremove && sudo apt autoclean sudo rm -rf /etc/mysql sudo rm -rf /var/lib/mysql
Optimize MYSQL configuration on Ubuntu Linux
For better MySQL performance, you may consider referencing this MYSQL configuration file. It has been optimized by experienced experts and could prove very useful for you.
Above is a summary of some commonly used commands to use MySQL using the command line, and terminal on Ubuntu and Linux. If you have any questions, please leave a comment below.