MySQL
is an open-source database management system, commonly installed as part of the popular
LAMP
(Linux, Apache, MySQL, PHP/Python/Perl) stack. It implements the relational model and uses Structured Query Language (better known as SQL) to manage its data.
This tutorial will go over how to install MySQL version 8.0 on an Ubuntu 20.04 server. By completing it, you will have a working relational database that you can use to build your next website or application.
Create a MySQL database quickly using
DigitalOcean Managed Databases
. Let DigitalOcean focus on maintaining, upgrading, and backups.
Run the following command to create a user that authenticates with caching_sha2_password. Be sure to change sammy to your preferred username and password to a strong password of your choosing:
Hello Mark, Thanks for the share of this tutorial, it helped me a lot, First time I do this without any issues and very clear all your steps on this article.
Appreciate it. Thank You.
Do anybody else have this issue upon running
sud apt install mysql-server
on a fresh droplet?
Setting up mysql-server-8.0 (8.0.32-0ubuntu0.22.10.2) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
2023-03-17T17:42:33.732349Z 0 [ERROR] [MY-011065] [Server] Unable to determine if daemon is running: Invalid argument (rc=0).
2023-03-17T17:42:33.733195Z 0 [ERROR] [MY-010946] [Server] Failed to start mysqld daemon. Check mysqld error log.
Warning: Unable to start the server.
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Job for mysql.service failed.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
Active: activating (auto-restart) (Result: oom-kill) since Fri 2023-03-17 17:42:36 UTC; 52ms ago
Process: 2883 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Process: 2891 ExecStart=/usr/sbin/mysqld (code=killed, signal=KILL)
Main PID: 2891 (code=killed, signal=KILL)
Status: "Server startup in progress"
CPU: 624ms
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Setting up libcgi-pm-perl (4.54-1) ...
Setting up libhtml-template-perl (2.97-2) ...
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-8.0; however:
Package mysql-server-8.0 is not configured yet.
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
Setting up libcgi-fast-perl (1:2.15-1) ...
Processing triggers for man-db (2.10.2-2) ...
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for libc-bin (2.36-0ubuntu4) ...
Errors were encountered while processing:
mysql-server-8.0
mysql-server
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)
I don’t see where I went wrong in copying-pasting 2 commands
I recently ran into the issue of not being able to log in after Step 2- mysql_secure_installation in WSL2
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
sudo mysql_secure_installation
# various prompts within this step
mysql -u root -p
mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
What worked was using TCP connection to connect rather than a socket connection
mysql -u root -p --protocol=tcp
OR use sudo
sudo mysql -u root -p
[sudo] password for vivek: <---- the sudo user password
Enter password: <---- mysql password
“sudo mysql_secure_installation” on a brand-new Ubuntu 20.04 provided by Digital Ocean gave the following error after attempting to set the root password:
“Failed! Error: SET PASSWORD has no significance for user ‘root’@‘localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.”
So to workaround this, use CTRL-C to cancel the mysql_secure_installation script and do the following:
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '<rootpassword>';
Then you can run “sudo mysql_secure_installation” again and this time, decline the option to change the root password so you can perform the other steps of the script.
Note that once this is set, you’ll access mysql with the password, like so, instead of just “sudo mysql”
I followed your tutorial on ubuntu 16.4 and it seems to be working all fine, now I have another question, my software instruction asks: the table engine must be “MyISAM”. With new MySQL versionit’s always InnoDB. Set “default-storage-engine” option to “MyISAM” in “/etc/mysql/my.cnf”
melvinpg7 • August 10, 2021
Hello Mark, Thanks for the share of this tutorial, it helped me a lot, First time I do this without any issues and very clear all your steps on this article. Appreciate it. Thank You.
vlada972010 • May 1, 2020
Hello,
How I can install MySQL 5? This is very important to me for using Magento 1 version.
Thank you.
OnStandBy • March 17, 2023
Do anybody else have this issue upon running
sud apt install mysql-server
on a fresh droplet?Jimmy Schwarz • January 25, 2023
Note, this will not work on the $4 instance but works fine on the $6 ones. If you have a $4 and upgrade to $6 it will work as well.
Vivek • October 13, 2022
I recently ran into the issue of not being able to log in after Step 2- mysql_secure_installation in WSL2
jaredsmith • May 31, 2022
“sudo mysql_secure_installation” on a brand-new Ubuntu 20.04 provided by Digital Ocean gave the following error after attempting to set the root password:
“Failed! Error: SET PASSWORD has no significance for user ‘root’@‘localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.”
So to workaround this, use CTRL-C to cancel the mysql_secure_installation script and do the following:
7a90d00da452a7235a973cf444f933 • February 16, 2022
This comment has been deleted
Ganesh Dhumal • January 19, 2022
Great Article it worked for me
sirEgghead • December 6, 2021
This comment has been deleted
mohadesehthm • January 19, 2021
hi
I followed your tutorial on ubuntu 16.4 and it seems to be working all fine, now I have another question, my software instruction asks: the table engine must be “MyISAM”. With new MySQL versionit’s always InnoDB. Set “default-storage-engine” option to “MyISAM” in “/etc/mysql/my.cnf”