MySQL on Ubuntu

Preliminaries

These notes are based on Ubuntu version 16.04, or equivalently, Linux Mint 18.

Editors

In many situations you will need to edit your own files or system configuration files (as root). I would recommend one of these two:
nano       non-graphical
gedit      graphical
For your files:
$ nano <MY FILE>
$ gedit <MY FILE>
For system files:
$ sudo nano <MY FILE>
$ sudo gedit <MY FILE>

MySQL

Before you do the installation, you need to choose a root password, not your system login password. You don't have to remember it forever, and you can change it easily. We'll say it's "foobar"

Install relevant the packages.
$ sudo apt-get install mysql-client mysql-server
Immediately you're presented with the password entry. Key it in, tab to OK and Enter.
----------------| Configuring mysql-server-5.7 |--------------------
| While not mandatory, it is highly recommended that you set a     |
| password for the MySQL administrative "root" user.               |
|                                                                  |
| If this field is left blank, the password will not be changed.   |
|                                                                  |
| New password for the MySQL "root" user:                          |
|                                                                  |
|                foobar                                            |
|                                                                  |
|                            <OK>                                  |
-------------------------------------------------------------------
This is followed by a confirmation dialog where you reenter the password.

Begin by confirming that you can get access the MySQL server as root:
$ mysql -u root -p
Enter password: foobar
Now you can store and use this password so that you don't want to have to remember it. Create the file:

~/.my.cnf
[client]
user=root
password='foobar'
select
You can use nano to do so:
$ nano ~/.my.cnf
You can now get in as root without giving the password:
$ mysql
mysql> quit

Change the root password

Pick a suitable NEW-PASSWORD, and change the root password to this as follows:
$ mysql
mysql> alter user root@localhost identified by 'NEW-PASSWORD';
mysql> quit
Make the change immediately in ~/.my.cnf before you forget it.

Create the test database

The notes refer to the standard database as the test database accessible by the guest user with empty password. Here is how we can create it:
$ mysql
mysql> create database test;
mysql> create user guest@localhost;
mysql> grant all on test.* to guest@localhost;
mysql> quit
Then test entry into the new database by:
$ mysql -u guest test -p
Enter password: ENTER
mysql> quit

PhpMyadmin

Install Apache/Php

This is overkill, but you may need some of these packages later anyway:
$ sudo apt-get install \
  apache2 php libapache2-mod-php php-cli php-mysql php-cgi \
  php-curl php-json php-mcrypt php-apcu php-gd php-xml \
  php-mbstring php-gettext phpmyadmin
Installation of phpmyadmin requires these steps:
  1. The first choice is to tell the configurator to pre-configure for a choice of web servers: Apache, Lighttpd. We want Apache, so tab to apache2 selection, hit space bar, getting:
    Web server to reconfigure automatically:
       [*] apache2
       [ ] lighttpd
    
    Then tab to OK and Enter.
  2. Next choice is asking whether to configure the database used by phpmyadmin for its management functions.
    Configure database for phpmyadmin with dbconfig-common?
    
    We want it. Tab to Yes and hit Enter.
  3. The next step is to provide the MySQL root password. Refer to ~/.my.cnf to confirm what you've set it to:
    Password of the database's administrative user:
    
    
    Tab to OK and hit enter.
  4. Give a confirmation of the password.
When you are done, confirm by activating the URL in a browser:
http://localhost/phpmyadmin
Access by entering the MySQL root user credentials:
user:     root
password: MYSQL-ROOT-PASSWORD


© Robert M. Kline