sudo apt install mysql-server -y<\/pre>\nOnce installed start and enable the MySQL service:<\/p>\n
systemctl start mysql.service && systemctl enable mysql.service<\/pre>\nTo check the status of the service:<\/p>\n
systemctl status mysql.service<\/pre>\nIf everything is ok, you should get the following output:<\/p>\n
root@host:~# systemctl status mysql.service\r\n\u25cf mysql.service - MySQL Community Server\r\n Loaded: loaded (\/lib\/systemd\/system\/mysql.service; enabled; vendor preset: enabled)\r\n Active: active (running) since Thu 2022-10-13 02:50:00 CDT; 8min ago\r\n Main PID: 239318 (mysqld)\r\n Status: \"Server is operational\"\r\n Tasks: 38 (limit: 4575)\r\n Memory: 361.4M\r\n CPU: 4.761s\r\n CGroup: \/system.slice\/mysql.service\r\n \u2514\u2500239318 \/usr\/sbin\/mysqld\r\n\r\nOct 13 02:49:58 host.test.vps systemd[1]: Starting MySQL Community Server...\r\nOct 13 02:50:00 host.test.vps systemd[1]: Started MySQL Community Server.<\/pre>\nNow, when MySQL database service is installed, we can start with the mysqladmin<\/b> commands. The syntax of mysqladmin<\/b> command is the following:<\/p>\nmysqladmin [options] command [command-arg] [command [command-arg]] ...<\/pre>\nTo Log in to the MySQL command line with the following command:<\/p>\n
mysql<\/pre>\nOn a fresh installation of MySQL, there is no password required, so you will receive the following output:<\/p>\n
root@host:~# mysql\r\nWelcome to the MySQL monitor. Commands end with ; or \\g.\r\nYour MySQL connection id is 8\r\nServer version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)\r\n\r\nCopyright (c) 2000, 2022, Oracle and\/or its affiliates.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql>\r\n<\/pre>\nIn the next sections, we will show you the most 10 used mysqladmin commands for database administration.<\/p>\n
<\/span>1. Set MySQL Root Password<\/span><\/h2>\nAs we said previously, a fresh installation of MySQL does not require a password. To set up MySQL root password with mysqladmin command, execute the following:<\/p>\n
mysqladmin -u root password StrongPasswordHere<\/pre>\nAfter executing this command, you should receive this warning:<\/p>\n
root@host:~# mysqladmin -u root password StrongPasswordHere\r\nmysqladmin: [Warning] Using a password on the command line interface can be insecure.\r\nWarning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.<\/pre>\nThis means that setting a new MySQL password using mysqladmin should be considered vulnerable, and it can be viewed in the history of the server commands. So you need to be careful and be sure not to share your server’s root password.<\/p>\n
<\/span>2. Create a Database<\/span><\/h2>\nTo create an empty database, execute the following command:<\/p>\n
mysqladmin -u root -p create testdb<\/pre>\nYou will be asked for the MySQL root password, and once inserted the database will be created successfully.<\/p>\n
root@host:~# mysqladmin -u root -p create testdb\r\nEnter password:\r\n\r\nmysql> show databases;\r\n+--------------------+\r\n| Database |\r\n+--------------------+\r\n| information_schema |\r\n| mysql |\r\n| performance_schema |\r\n| sys |\r\n| testdb |\r\n+--------------------+\r\n<\/pre>\n<\/span>3. Drop Database<\/span><\/h2>\nTo drop the database with mysqladmin command, execute the following:<\/p>\n
mysqladmin -u root -p drop testdb<\/pre>\nYou will be asked for the root password<\/p>\n
root@host:~# mysqladmin -u root -p drop testdb\r\nEnter password:\r\nDropping the database is potentially a very bad thing to do.\r\nAny data stored in the database will be destroyed.\r\n\r\nDo you really want to drop the 'testdb' database [y\/N] y\r\nDatabase \"testdb\" dropped\r\n<\/pre>\n<\/span>4. Check Active Processes<\/span><\/h2>\nTo check the active threads, execute the following command:<\/p>\n
mysqladmin -u root -p processlist<\/pre>\nYou will get a table with output similar to this:<\/p>\n
root@host:~# mysqladmin -u root -p processlist\r\nEnter password:\r\n+----+-----------------+-----------+----+---------+-------+------------------------+------------------+\r\n| Id | User | Host | db | Command | Time | State | Info |\r\n+----+-----------------+-----------+----+---------+-------+------------------------+------------------+\r\n| 5 | event_scheduler | localhost | | Daemon | 19834 | Waiting on empty queue | |\r\n| 14 | root | localhost | | Query | 0 | init | show processlist |\r\n+----+-----------------+-----------+----+---------+-------+------------------------+------------------+\r\n<\/pre>\n<\/span>5. Check the Status of the MySQL Server<\/span><\/h2>\nTo check the status of the MySQL server, execute the following command:<\/p>\n
mysqladmin -u root -p status<\/pre>\nYou should receive output similar to this:<\/p>\n
root@host:~# mysqladmin -u root -p status\r\nEnter password:\r\nUptime: 19978 Threads: 2 Questions: 18 Slow queries: 0 Opens: 167 Flush tables: 3 Open tables: 86 Queries per second avg: 0.000\r\n<\/pre>\n