https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04
siddjain@engblog:~$ sudo apt update
Hit:1 http://azure.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://azure.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://azure.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:5 http://azure.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [753 kB]
Get:6 http://azure.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [271 kB]
Get:7 http://azure.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [15.7 kB]
Get:8 http://azure.archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [4956 B]
Get:9 http://azure.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1012 kB]
Get:10 http://azure.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [312 kB]
Get:11 http://azure.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [7884 B]
Get:12 http://azure.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [3944 B]
siddjain@engblog:~$ sudo apt install mysql-server
Unpacking libcgi-fast-perl (1:2.13-1) …
Selecting previously unselected package libencode-locale-perl.
Preparing to unpack …/07-libencode-locale-perl_1.05-1_all.deb …
Unpacking libencode-locale-perl (1.05-1) …
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack …/08-libhtml-template-perl_2.97-1_all.deb …
Unpacking libhtml-template-perl (2.97-1) …
Selecting previously unselected package libtimedate-perl.
Preparing to unpack …/09-libtimedate-perl_2.3000-2_all.deb …
Unpacking libtimedate-perl (2.3000-2) …
Selecting previously unselected package libhttp-date-perl.
Preparing to unpack …/10-libhttp-date-perl_6.02-1_all.deb …
Unpacking libhttp-date-perl (6.02-1) …
Selecting previously unselected package libio-html-perl.
Preparing to unpack …/11-libio-html-perl_1.001-1_all.deb …
Unpacking libio-html-perl (1.001-1) …
Selecting previously unselected package liblwp-mediatypes-perl.
Preparing to unpack …/12-liblwp-mediatypes-perl_6.02-1_all.deb …
Unpacking liblwp-mediatypes-perl (6.02-1) …
Selecting previously unselected package libhttp-message-perl.
Preparing to unpack …/13-libhttp-message-perl_6.14-1_all.deb …
Unpacking libhttp-message-perl (6.14-1) …
Selecting previously unselected package mysql-server.
Preparing to unpack …/14-mysql-server_5.7.27-0ubuntu0.18.04.1_all.deb …
Unpacking mysql-server (5.7.27-0ubuntu0.18.04.1) …
Setting up libhtml-tagset-perl (3.20-3) …
Setting up libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) …
Setting up libencode-locale-perl (1.05-1) …
Setting up libtimedate-perl (2.3000-2) …
Setting up libio-html-perl (1.001-1) …
Setting up liblwp-mediatypes-perl (6.02-1) …
Setting up libaio1:amd64 (0.3.110-5ubuntu0.1) …
Setting up liburi-perl (1.73-1) …
Setting up libhtml-parser-perl (3.72-3build1) …
Setting up libcgi-pm-perl (4.38-1) …
Setting up mysql-client-core-5.7 (5.7.27-0ubuntu0.18.04.1) …
Setting up libfcgi-perl (0.78-2build1) …
Setting up libhttp-date-perl (6.02-1) …
Setting up libhtml-template-perl (2.97-1) …
Setting up mysql-server-core-5.7 (5.7.27-0ubuntu0.18.04.1) …
Setting up libcgi-fast-perl (1:2.13-1) …
Setting up libhttp-message-perl (6.14-1) …
Setting up mysql-client-5.7 (5.7.27-0ubuntu0.18.04.1) …
Setting up mysql-server-5.7 (5.7.27-0ubuntu0.18.04.1) …
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)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Setting up mysql-server (5.7.27-0ubuntu0.18.04.1) …
Processing triggers for libc-bin (2.27-3ubuntu1) …
Processing triggers for systemd (237-3ubuntu10.26) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
Processing triggers for ureadahead (0.100.0-21) …
siddjain@engblog:~$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.
New password: enter your password for root user
Re-enter new password: re-enter the password
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
– Dropping test database…
Success.
– Removing privileges on test database…
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
siddjain@engblog:~$ cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# – “/etc/mysql/my.cnf” to set global options,
# – “~/.my.cnf” to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with –help to get a list of available options and with
# –print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with ‘.cnf’, otherwise they’ll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
let’s change the data directory. We have attached a 1TB disk and mounted it at /data. Let’s store our data there so that we can back it up and attach to a different VM if need be.
https://www.fromdual.com/mysql-configuration-file-sample
Find the line in the [mysqld] block that begins with datadir=, which is separated from the block heading with several comments. Change the path which follows to reflect the new location. In addition, since the socket was previously located in the data directory, we’ll need to update it to the new location:
so change the file to
siddjain@engblog:~$ cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# – “/etc/mysql/my.cnf” to set global options,
# – “~/.my.cnf” to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with –help to get a list of available options and with
# –print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with ‘.cnf’, otherwise they’ll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
datadir=/data/mysql
socket=/var/run/mysqld/mysqld.sock
[client]
port=3306
socket=/var/run/mysqld/mysqld.sock
above is assuming you have a mysql.sock under /var/run/mysqld (you should. check it)
Now when you run mysqld –initialize you will get error:
siddjain@engblog:~$ mysqld –initialize
mysqld: Can’t create directory ‘/data/mysql/’ (Errcode: 13 – Permission denied)
2019-10-18T17:27:43.696325Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T17:27:43.704308Z 0 [ERROR] Aborting
siddjain@engblog:~$ ls -al /data
total 24
drwxr-xr-x 3 root root 4096 Oct 18 16:37 .
drwxr-xr-x 24 root root 4096 Oct 18 16:54 ..
drwx—— 2 root root 16384 Oct 18 16:37 lost+found
creating the /data/mysql will also not work
siddjain@engblog:~$ sudo mkdir /data/mysql
siddjain@engblog:~$ mysqld –initialize
mysqld: Can’t create directory ‘/data/mysql/’ (Errcode: 17 – File exists)
2019-10-18T17:30:01.441271Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T17:30:01.442894Z 0 [ERROR] Aborting
I found the solution to the problem in https://bugs.mysql.com/bug.php?id=82281. Here are the steps to fix it:
siddjain@engblog:~$ aa-disable /usr/sbin/mysqld
Command ‘aa-disable’ not found, but can be installed with:
sudo apt install apparmor-utils
siddjain@engblog:~$ sudo apt install apparmor-utils
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
python3-apparmor python3-libapparmor
Suggested packages:
vim-addon-manager
The following NEW packages will be installed:
apparmor-utils python3-apparmor python3-libapparmor
0 upgraded, 3 newly installed, 0 to remove and 47 not upgraded.
Need to get 157 kB of archives.
After this operation, 961 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://azure.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-libapparmor amd64 2.12-4ubuntu5.1 [26.8 kB]
Get:2 http://azure.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-apparmor amd64 2.12-4ubuntu5.1 [79.5 kB]
Get:3 http://azure.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apparmor-utils amd64 2.12-4ubuntu5.1 [50.6 kB]
Fetched 157 kB in 0s (1270 kB/s)
Selecting previously unselected package python3-libapparmor.
(Reading database … 56820 files and directories currently installed.)
Preparing to unpack …/python3-libapparmor_2.12-4ubuntu5.1_amd64.deb …
Unpacking python3-libapparmor (2.12-4ubuntu5.1) …
Selecting previously unselected package python3-apparmor.
Preparing to unpack …/python3-apparmor_2.12-4ubuntu5.1_amd64.deb …
Unpacking python3-apparmor (2.12-4ubuntu5.1) …
Selecting previously unselected package apparmor-utils.
Preparing to unpack …/apparmor-utils_2.12-4ubuntu5.1_amd64.deb …
Unpacking apparmor-utils (2.12-4ubuntu5.1) …
Setting up python3-libapparmor (2.12-4ubuntu5.1) …
Setting up python3-apparmor (2.12-4ubuntu5.1) …
Setting up apparmor-utils (2.12-4ubuntu5.1) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
siddjain@engblog:~$ aa-disable /usr/sbin/mysqld
Cannot write to profile directory.
Please run as a user with appropriate permissions.
ERROR: Cannot write to profile directory: /etc/apparmor.d
siddjain@engblog:~$ sudo aa-disable /usr/sbin/mysqld
Disabling /usr/sbin/mysqld.
siddjain@engblog:~$ mysqld –initialize
mysqld: Can’t create directory ‘/data/mysql/’ (Errcode: 13 – Permission denied)
2019-10-18T17:34:44.069428Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T17:34:44.070995Z 0 [ERROR] Aborting
siddjain@engblog:~$ sudo mysqld –initialize
siddjain@engblog:~$ ls /data/mysql
ls: cannot open directory ‘/data/mysql’: Permission denied
siddjain@engblog:~$ sudo ls -al /data/mysql
total 110628
drwxr-x— 5 mysql mysql 4096 Oct 18 17:34 .
drwxr-xr-x 4 root root 4096 Oct 18 17:34 ..
-rw-r—– 1 mysql mysql 56 Oct 18 17:34 auto.cnf
-rw-r—– 1 mysql mysql 424 Oct 18 17:34 ib_buffer_pool
-rw-r—– 1 mysql mysql 50331648 Oct 18 17:34 ib_logfile0
-rw-r—– 1 mysql mysql 50331648 Oct 18 17:34 ib_logfile1
-rw-r—– 1 mysql mysql 12582912 Oct 18 17:34 ibdata1
drwxr-x— 2 mysql mysql 4096 Oct 18 17:34 mysql
drwxr-x— 2 mysql mysql 4096 Oct 18 17:34 performance_schema
drwxr-x— 2 mysql mysql 12288 Oct 18 17:34 sys
Next do these steps from https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04
mysql>exit;
Oct 18 17:07:46 engblog systemd[1]: Started MySQL Community Server.
log file is at /var/log/mysql/error.log.1
MySQL articles and tips https://www.artfulsoftware.com/infotree/mysqltips.php
mysql login stops working https://askubuntu.com/questions/567590/mysql-server-not-recognizing-correct-password