mindcurrent / djanky-django

Daniel's Janky Attempt at a Django RESTful API Server
0 stars 1 forks source link

Install MySQL Client/Server #1

Open dpcunningham opened 4 years ago

dpcunningham commented 4 years ago

Django, for our usage pattern, will require MySQL.

This was problematic enough (and diagnostics were poor enough) that I wanted to make some notes to save headaches for anyone repeating this process.

See comments below...

dpcunningham commented 4 years ago

Determine where we are & what we's dealing with:

dpc@LT3-Insp17-2017:~$ cat /etc/issue
Linux Mint 19.1 Tessa

dpc@LT3-Insp17-2017:~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

dpc@LT3-Insp17-2017:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

dpc@LT3-Insp17-2017:~$ mysql  --version  # Do we gots it already by default?
mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper
dpcunningham commented 4 years ago

Install MySQL Server:

www.mysql.com is all Corporate Oracle BS. www.mysql.org resolves to dev.mysql.com.

I'm concerned about the mismatch between client & server versions (5.7 to 8.0).

These two articles gave a better match between my client version and the server version:

I went with the first one:

dpc@LT3-Insp17-2017:~$ sudo apt-get install mysql-server-5.7
The following packages were automatically installed and are no longer required:
  libexpat1-dev libpango1.0-0 libpangox-1.0-0 libpython2.7-dev python-pyinotify python2.7-dev
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 439 not upgraded.

dpc@LT3-Insp17-2017:~$ sudo apt autoremove

dpc@LT3-Insp17-2017:~$ sudo mysql_secure_installation

dpc@LT3-Insp17-2017:~$ sudo systemctl status mysql.service

dpc@LT3-Insp17-2017:~$ sudo service mysql stop
dpc@LT3-Insp17-2017:~$ sudo service mysql start
dpc@LT3-Insp17-2017:~$ sudo service mysql restart
dpcunningham commented 4 years ago

After installation I went through about an hour of this BS...

dpc@LT3-Insp17-2017:~$ mysql -u root -p -h localhost
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Turns out there's some obscure default config stuffs, per StackOverflow:

Stack Overflow: ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Some systems like Ubuntu, mysql is using by default the UNIX auth_socket plugin.

Basically means that: db_users using it, will be "auth" by the system user credentials. You can see if your root user is set up like this by doing the following:

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> SELECT User, Host, plugin FROM mysql.user;

+------------------+-----------------------+
| User             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+

As you can see in the query, the root user is using the auth_socket plugin

There are 2 ways to solve this:

Option 1:

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;

$ service mysql restart

Option 2: (replace YOUR_SYSTEM_USER with the username you have)

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY '';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost';
mysql> UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER';
mysql> FLUSH PRIVILEGES;
mysql> exit;

$ service mysql restart

Remember that if you use option #2 you'll have to connect to mysql as your system username (mysql -u YOUR_SYSTEM_USER)

I went with option 1 -- which has a possible extra action required later on:

Option 1 worked for me. But then I also needed to run sudo gedit /etc/phpmyadmin/config.inc.php. Then I did a search for AllowNoPassword and uncommented both lines that contained it. Then I was able to login as root with no password.

dpcunningham commented 4 years ago

Deal with BS from the optional password validator.

mysql> CREATE USER 'django.dev'@'localhost' IDENTIFIED BY 'my-clever-22-bits-o-entropy';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

The mysql_secure_installation password validator gives everyone headaches, so: