{"id":392,"date":"2025-05-15T08:50:15","date_gmt":"2025-05-15T06:50:15","guid":{"rendered":"https:\/\/www.24x7serverguard.com\/blog\/?p=392"},"modified":"2025-05-15T09:19:31","modified_gmt":"2025-05-15T07:19:31","slug":"how-to-install-mysql-on-ubuntu-latest-version-22-04-24-04","status":"publish","type":"post","link":"https:\/\/www.24x7serverguard.com\/blog\/installation\/how-to-install-mysql-on-ubuntu-latest-version-22-04-24-04\/","title":{"rendered":"How to Install MySQL on Ubuntu (Latest Version \u2013 22.04\/24.04)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">MySQL is a widely used open-source relational database. In this guide, you\u2019ll learn how to install the latest MySQL version (currently <strong>MySQL 8.0<\/strong>) on Ubuntu.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step 1: Update Your System<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start by updating your system packages to ensure everything is up to date:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step 2: Add MySQL APT Repository (Optional but Recommended)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu\u2019s default repo may not have the latest MySQL version. You can add the official MySQL APT repository to ensure you&#8217;re installing the latest release:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/dev.mysql.com\/get\/mysql-apt-config_0.8.29-1_all.deb<br>sudo dpkg -i mysql-apt-config_0.8.29-1_all.deb<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">During the setup, select the MySQL version (default is 8.0), then choose &#8220;OK&#8221; to proceed.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Update package info again after adding the repo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step 3: Install MySQL Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now install MySQL server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install mysql-server -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The installer will automatically configure and start MySQL.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step 4: Secure MySQL Installation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the included security script to harden your MySQL server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql_secure_installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll be prompted to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set root password<\/li>\n\n\n\n<li>Remove anonymous users<\/li>\n\n\n\n<li>Disallow root login remotely<\/li>\n\n\n\n<li>Remove test database<\/li>\n\n\n\n<li>Reload privilege tables<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Recommended:<\/strong> Answer <code>Y<\/code> to all prompts for maximum security.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step 5: Check MySQL Status<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that MySQL is active and running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status mysql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see: <code>active (running)<\/code>. Press <code>q<\/code> to exit.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step 6: Log In to MySQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To access MySQL shell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This logs in as the root user using socket authentication.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd04 Optional: Enable Password Authentication for Root<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to use <code>mysql -u root -p<\/code> with a password:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">ALTER USER<\/mark> '<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">root'@'localhost<\/mark>' IDENTIFIED <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">WITH <\/mark>mysql_native_password <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">BY <\/mark>'<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">YourStrongPassword<\/mark>';<br>FLUSH PRIVILEGES;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd27 Useful Commands<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Task<\/th><th>Command<\/th><\/tr><\/thead><tbody><tr><td>Restart MySQL<\/td><td><code>sudo systemctl restart mysql<\/code><\/td><\/tr><tr><td>Enable on boot<\/td><td><code>sudo systemctl enable mysql<\/code><\/td><\/tr><tr><td>MySQL version<\/td><td><code>mysql --version<\/code><\/td><\/tr><tr><td>MySQL shell<\/td><td><code>sudo mysql<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\ude80 MySQL is Ready!<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your MySQL server is now fully installed and secured on Ubuntu. You can start creating databases and users for your applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL is a widely used open-source relational database. In this guide, you\u2019ll learn how to install the latest MySQL version (currently MySQL 8.0) on Ubuntu. \u2705 Step 1: Update Your System Start by updating your system packages to ensure everything is up to date: \u2705 Step 2: Add MySQL APT Repository (Optional but Recommended) Ubuntu\u2019s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":393,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[367,368],"class_list":["post-392","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-installation","tag-how-to-install-mysql-on-ubuntu","tag-version-22-04-24-04"],"_links":{"self":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":3,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":397,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/392\/revisions\/397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media\/393"}],"wp:attachment":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}