forked from littlebizzy/slickstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss-install-mysql.txt
560 lines (457 loc) · 27.7 KB
/
ss-install-mysql.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
#!/bin/bash
####################################################################################################
#### author: SlickStack ############################################################################
#### link: https://slickstack.io ###################################################################
#### mirror: http://mirrors.slickstack.io/ss-install-mysql.txt #####################################
#### path: /var/www/ss-install-mysql ###############################################################
#### destination: n/a (not a boilerplate) ##########################################################
#### purpose: Reinstalls the entire MySQL module for SlickStack servers (idempotent) ###############
#### module version: Ubuntu 20.04 LTS + MySQL 8.0.x ################################################
####################################################################################################
## MYSQL IS PHASING OUT NATIVE PASSWORDS IN FAVOR OF UNIX SOCKETS AND/OR SHA2 HASHING ##
## WE USE SOCKETS FOR CORE SCRIPTS AND AIM TO USE TCP/SSL/SHA2 FOR WORDPRESS ##
## include SlickStack configuration ##
source /var/www/ss-config
####################################################################################################
#### SlickStack: Critical Bash Functions (Aliases) For This Script To Work #########################
####################################################################################################
## the below functions are hardcoded into every SlickStack script to ensure reliability ##
## this also speeds up processing times by avoiding repeated inline commands ##
## variables ##
UBUNTU_VERSION=`lsb_release -rs`
## apt alias flags ##
function apt {
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
command /usr/bin/apt --yes --quiet --option Dpkg::Options::=--force-confold --option Dpkg::Options::=--force-confdef "$@"
}
## add-apt-repository alias flags ##
function add-apt-repository {
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
command /usr/bin/add-apt-repository --yes "$@"
}
## wget alias flags ##
function wget {
command wget --no-check-certificate --no-cache --no-cookies --tries=3 --timeout=15 "$@"
}
## mysql alias flags ##
function mysql {
command mysql --user=root --host=localhost --protocol=socket --port=3306 --force "$@"
}
## cp alias flags ##
function cp {
command cp -R -f -d --no-preserve=mode,ownership "$@"
}
## rsync alias flags ##
function rsync {
command rsync -aI --ignore-errors "$@"
}
## unzip alias flags ##
function unzip {
command unzip -o "$@"
}
## mkdir alias flags ##
function mkdir {
command mkdir -p "$@"
}
## rm alias flags ##
function rm {
command rm -R -f "$@"
}
## ln alias flags ##
function ln {
command ln -s -f "$@"
}
####################################################################################################
#### SlickStack: Pretty Colors Make The Shell More Pleasing ########################################
####################################################################################################
## these color variables help maintain cleaner and prettier Bash scripts in SlickStack ##
## we substitute e.g. ${BLUE} within an echo line then use ${NOCOLOR} to revert ##
## pretty Bash colors ##
NOCOLOR='\033[0m'
DARKRED='\033[0;31m'
LIGHTRED='\033[1;31m'
ORANGE='\033[0;33m'
YELLOW='\033[1;33m'
DARKGREEN='\033[0;32m'
LIGHTGREEN='\033[1;32m'
DARKCYAN='\033[0;36m'
LIGHTCYAN='\033[1;36m'
DARKBLUE='\033[0;34m'
LIGHTBLUE='\033[1;34m'
DARKPURPLE='\033[0;35m'
LIGHTPURPLE='\033[1;35m'
DARKGRAY='\033[1;30m'
LIGHTGRAY='\033[0;37m'
WHITE='\033[1;37m'
## pretty Bash styles ##
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
####################################################################################################
#### SS-Install-MySQL: Cleanup Any Existing MySQL Packages + Data ##################################
####################################################################################################
## first we backup the live database (and /var/lib/mysql) and kill any leftover processes ##
## then we proceed with purge/cleanup of MySQL packages to pepare a clean install ##
## run ss-dump (copies /var/lib/mysql to /var/www/meta/mysql.bak) ##
source /var/www/ss-dump
## TEMP ##
# echo -e "${YELLOW}SS-INSTALL-MYSQL: SINCE SS_BUILD JULY2020B MYSQL 8.0 USERS MIGHT NOT INSTALL COMPLETELY (PLEASE FINISH INSTALL MANUALLY IF ANY ISSUES)...${NOCOLOR}"
sleep 10s
## stop MySQL ##
/etc/init.d/mysql* stop
sleep 15s
## kill any remaining MySQL processes ##
killall mysql*
sleep 15s
## purge all MySQL packages and remove any previous MySQL configuration files ##
apt purge ^mysql
# rm /etc/mysql/*
# rm /var/lib/mysql/*
## cleanup potential conflicting files ##
apt autoremove
apt autoclean
## update repo cache ##
apt update
####################################################################################################
#### SS-Install-MySQL: Prepare Root User Authentication (Debconf) ##################################
####################################################################################################
## here we prepare the MySQL root password using the Debian/Ubuntu debconf utilities ##
## all SlickStack scripts connect to MySQL via root@localhost using sockets ##
# repair debconf (see: sudo debconf-show mysql-community-server-8.0) ##
sudo /usr/share/debconf/fix_db.pl
## purge any previous debconf/MySQL data ##
sudo echo PURGE | sudo debconf-communicate mysql-community-server
sudo echo PURGE | sudo debconf-communicate mysql-server
# sudo echo "mysql-community-server mysql-community-server/remove-data-dir boolean true" | sudo debconf-set-selections
## prepare root password for apt (PSA: sudo the shit out of these or it will fail) ##
# if [[ "${UBUNTU_VERSION}" = "20.04" || -z "${UBUNTU_VERSION}" ]]; then
# sudo echo "mysql-community-server mysql-community-server/root-pass password ${DB_PASSWORD_ROOT}" | sudo debconf-set-selections
# sudo echo "mysql-community-server mysql-community-server/re-root-pass password ${DB_PASSWORD_ROOT}" | sudo debconf-set-selections
# sudo echo "mysql-community-server mysql-server/default-auth-override select Use Legacy Authentication Method (Retain MySQL 5.x Compatibility)" | sudo debconf-set-selections
# fi
####################################################################################################
#### SS-Install-MySQL: Install MySQL Package #######################################################
####################################################################################################
## this script will only install the MySQL packages if not set to false in ss-config ##
## remote database environments might not require localhost MySQL installed ##
## only run ss-install-mysql if not set to false in ss-config ##
# if [[ "$SS_MYSQL" != "false" ]]; then
# fi
## install MySQL 8.0 if server is running Ubuntu 20.04 ##
if [[ "${UBUNTU_VERSION}" = "20.04" || -z "${UBUNTU_VERSION}" ]]; then
apt install mysql-server-8.0
fi
## install MySQL 5.7 if server is running Ubuntu 18.04 ##
if [[ "${UBUNTU_VERSION}" = "18.04" ]]; then
apt install mysql-server-5.7
fi
####################################################################################################
#### SS-Install-MySQL: Configure Root + Admin User (Localhost/IPv4/IPv6) ###########################
####################################################################################################
## manually secure MySQL (noninteractive version of the mysql_secure_installation wizard) ##
## caching_sha2_password is better but mysql_native_password is more compatible ##
## mysql_secure_installation (alternative) via root@localhost ##
sudo mysql -e "UNINSTALL COMPONENT 'file://component_validate_password';" ## not installed by default on MySQL 8.0.x
sudo mysql -e "UNINSTALL PLUGIN validate_password;" ## not installed by default on MySQL 8.0.x
sudo mysql -e "DELETE FROM mysql.user WHERE user='';"
sudo mysql -e "DELETE FROM mysql.user WHERE user='root' AND host NOT IN ('localhost', '127.0.0.1', '::1');"
sudo mysql -e "DELETE FROM mysql.user WHERE user='admin' AND host NOT IN ('localhost', '127.0.0.1', '::1');"
sudo mysql -e "DROP DATABASE IF EXISTS test;"
####################################################################################################
#### SS-Install-MySQL: Configure WordPress Database + User + Privileges ############################
####################################################################################################
## we use root@localhost (auth_socket) and user@127.0.0.1 (TCP) for WordPress database ##
## the superuser admin@127.0.0.1 is also created to be used with phpMyAdmin, etc ##
## create WordPress database ##
sudo mysql -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};"
## create admin superuser (can be used with Adminer/phpMyAdmin) ##
sudo mysql -e "ALTER USER IF EXISTS 'admin'@'localhost' IDENTIFIED WITH caching_sha2_password BY '${DB_PASSWORD_ROOT}';"
sudo mysql -e "ALTER USER IF EXISTS 'admin'@'127.0.0.1' IDENTIFIED WITH caching_sha2_password BY '${DB_PASSWORD_ROOT}';"
sudo mysql -e "ALTER USER IF EXISTS 'admin'@'::1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD_ROOT}';"
sudo mysql -e "CREATE USER IF NOT EXISTS 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD_ROOT}';"
sudo mysql -e "CREATE USER IF NOT EXISTS 'admin'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD_ROOT}';"
sudo mysql -e "CREATE USER IF NOT EXISTS 'admin'@'::1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD_ROOT}';"
## grant admin superuser all privileges on all databases (localhost/IPv4/IPv6) ##
sudo mysql -e "GRANT ALL ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;"
sudo mysql -e "GRANT ALL ON *.* TO 'admin'@'127.0.0.1' WITH GRANT OPTION;"
sudo mysql -e "GRANT ALL ON *.* TO 'admin'@'::1' WITH GRANT OPTION;"
## create limited user for WordPress database ##
sudo mysql -e "ALTER USER IF EXISTS '${DB_USER}'@'localhost' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';"
sudo mysql -e "ALTER USER IF EXISTS '${DB_USER}'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';"
sudo mysql -e "ALTER USER IF EXISTS '${DB_USER}'@'::1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';"
sudo mysql -e "CREATE USER IF NOT EXISTS '${DB_USER}'@'localhost' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';"
sudo mysql -e "CREATE USER IF NOT EXISTS '${DB_USER}'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';"
sudo mysql -e "CREATE USER IF NOT EXISTS '${DB_USER}'@'::1' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';"
## grant limited user privileges on WordPress database only (localhost/IPv4/IPv6) ##
sudo mysql -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_USER}'@'localhost';"
sudo mysql -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_USER}'@'127.0.0.1';"
sudo mysql -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_USER}'@'::1';"
## install auth_socket plugin ##
sudo mysql -e "INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';"
## create sudo@localhost user via auth_socket ##
sudo mysql -e "ALTER USER IF EXISTS '${SUDO_USER}'@'localhost' IDENTIFIED WITH auth_socket BY '';"
sudo mysql -e "CREATE USER IF NOT EXISTS '${SUDO_USER}'@'localhost' IDENTIFIED WITH auth_socket BY '';"
sudo mysql -e "GRANT ALL ON *.* TO '${SUDO_USER}'@'localhost' WITH GRANT OPTION;"
## ensure root@localhost user is using auth_socket ##
sudo mysql -e "ALTER USER IF EXISTS 'root'@'localhost' IDENTIFIED WITH auth_socket BY '';"
sudo mysql -e "CREATE USER IF NOT EXISTS 'root'@'localhost' IDENTIFIED WITH auth_socket BY '';"
sudo mysql -e "GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION;"
sudo mysql -e "FLUSH PRIVILEGES;"
####################################################################################################
#### SS-Install-MySQL: Optimize My.cnf (MySQL Configuration) Settings ##############################
####################################################################################################
## here we overwrite the default my.cnf with an optimized version (sub-config disabled) ##
## all MySQL logs should be found under /var/www/logs/ after install complete ##
## stop MySQL ##
/etc/init.d/mysql* stop
sleep 15s
# killall mysql*
# sleep 15s
## cleanup leftover files ##
rm /tmp/my.cnf
## install custom my.cnf config file ##
wget -O /tmp/my.cnf http://mirrors.slickstack.io/mysql/my-cnf.txt
#### MySQL Settings ####
## SQL mode ##
if [[ -z "$SQL_MODE" ]]; then
sed -i "s/@SQL_MODE/STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION/g" /tmp/my.cnf
else
sed -i "s/@SQL_MODE/${SQL_MODE}/g" /tmp/my.cnf
fi
## max allowed packet ##
if [[ -z "$SQL_MAX_ALLOWED_PACKET" ]]; then
sed -i "s/@SQL_MAX_ALLOWED_PACKET/256M/g" /tmp/my.cnf
else
sed -i "s/@SQL_MAX_ALLOWED_PACKET/${SQL_MAX_ALLOWED_PACKET}/g" /tmp/my.cnf
fi
## connect timeout ##
if [[ -z "$SQL_CONNECT_TIMEOUT" ]]; then
sed -i "s/@SQL_CONNECT_TIMEOUT/30/g" /tmp/my.cnf
else
sed -i "s/@SQL_CONNECT_TIMEOUT/${SQL_CONNECT_TIMEOUT}/g" /tmp/my.cnf
fi
## wait timeout ##
if [[ -z "$SQL_WAIT_TIMEOUT" ]]; then
sed -i "s/@SQL_WAIT_TIMEOUT/3600/g" /tmp/my.cnf
else
sed -i "s/@SQL_WAIT_TIMEOUT/${SQL_WAIT_TIMEOUT}/g" /tmp/my.cnf
fi
## interactive timeout ##
if [[ -z "$SQL_INTERACTIVE_TIMEOUT" ]]; then
sed -i "s/@SQL_INTERACTIVE_TIMEOUT/43200/g" /tmp/my.cnf
else
sed -i "s/@SQL_INTERACTIVE_TIMEOUT/${SQL_INTERACTIVE_TIMEOUT}/g" /tmp/my.cnf
fi
## net read timeout ##
if [[ -z "$SQL_NET_READ_TIMEOUT" ]]; then
sed -i "s/@SQL_NET_READ_TIMEOUT/30/g" /tmp/my.cnf
else
sed -i "s/@SQL_NET_READ_TIMEOUT/${SQL_NET_READ_TIMEOUT}/g" /tmp/my.cnf
fi
## net write timeout ##
if [[ -z "$SQL_NET_WRITE_TIMEOUT" ]]; then
sed -i "s/@SQL_NET_WRITE_TIMEOUT/60/g" /tmp/my.cnf
else
sed -i "s/@SQL_NET_WRITE_TIMEOUT/${SQL_NET_WRITE_TIMEOUT}/g" /tmp/my.cnf
fi
## set InnoDB buffer pool size (supports "auto" or manual via ss-config) ##
PERCENT_RAM_MB=$(free -m | awk 'NR==2{printf "%d", $2*0.50 }')
if [[ "$INNODB_BUFFER_POOL_SIZE" == "auto" ]]; then
sed -i "s/@INNODB_BUFFER_POOL_SIZE/${PERCENT_RAM_MB}M/g" /tmp/my.cnf
else
sed -i "s/@INNODB_BUFFER_POOL_SIZE/${INNODB_BUFFER_POOL_SIZE}/g" /tmp/my.cnf
fi
## set InnoDB flush method ##
if [[ -z "$INNODB_FLUSH_METHOD" ]]; then
sed -i "s/@INNODB_FLUSH_METHOD/O_DIRECT/g" /tmp/my.cnf
else
sed -i "s/@INNODB_FLUSH_METHOD/${INNODB_FLUSH_METHOD}/g" /tmp/my.cnf
fi
## set InnoDB log file size ##
if [[ -z "$INNODB_LOG_FILE_SIZE" ]]; then
sed -i "s/@INNODB_LOG_FILE_SIZE/256M/g" /tmp/my.cnf
else
sed -i "s/@INNODB_LOG_FILE_SIZE/${INNODB_LOG_FILE_SIZE}/g" /tmp/my.cnf
fi
## set InnoDB log files in group ##
if [[ -z "$INNODB_LOG_FILES_IN_GROUP" ]]; then
sed -i "s/@INNODB_LOG_FILES_IN_GROUP/1/g" /tmp/my.cnf
else
sed -i "s/@INNODB_LOG_FILES_IN_GROUP/${INNODB_LOG_FILES_IN_GROUP}/g" /tmp/my.cnf
fi
## set InnoDB flush_log_at_trx_commit ##
if [[ "$INNODB_FLUSH_LOG_AT_TRX_COMMIT" == "false" ]]; then
sed -i "s/@INNODB_FLUSH_LOG_AT_TRX_COMMIT/0/g" /tmp/my.cnf
else
sed -i "s/@INNODB_FLUSH_LOG_AT_TRX_COMMIT/1/g" /tmp/my.cnf
fi
## safe/clean/slow shutdown MySQL before update config ##
# /etc/init.d/mysql stop ## too fast
## copy files to their destinations ##
cp /tmp/my.cnf /etc/mysql/my.cnf
## reset permissions ##
# chown root:root /etc/mysql/my.cnf
# chmod 0777 /etc/mysql/my.cnf ## symlink to /etc/alternatives/my.cnf
## reset permissions ##
# mkdir /var/run/mysqld
# chown mysql:mysql /var/run/mysqld
# chmod -R 0775 /var/run/mysqld
# chown mysql:mysql /var/www/logs/mysql*.log
# chown mysql:mysql /var/lib/mysql ## drwx------
# chown mysql:mysql /var/lib/mysql-files ## drwx------
# chown mysql:mysql /var/lib/mysql-keyring ## drwx------
# chown root:root /var/lib/mysql-upgrade ## must be root:root ## drwxr-xr-x
## create MySQL log files if they do not exist ##
if [ ! -f "/var/www/logs/mysql-gen.log" ]; then touch "/var/www/logs/mysql-gen.log"; fi
if [ ! -f "/var/www/logs/mysql-error.log" ]; then touch "/var/www/logs/mysql-error.log"; fi
if [ ! -f "/var/www/logs/mysql-slow.log" ]; then touch "/var/www/logs/mysql-slow.log"; fi
## restart MySQL ##
/etc/init.d/mysql* restart
## cleanup tmp files ##
rm /tmp/init-mysql.txt*
rm /var/run/mysqld.bak*
####################################################################################################
#### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ###############
####################################################################################################
## mysql alias flags ##
# command mysql --no-defaults --user=root --password=$DB_PASSWORD_ROOT --host=localhost --protocol=socket --socket=/var/run/mysqld/mysqld.sock --port=3306 --force "$@"
# sudo mysql -e "ALTER USER IF EXISTS 'root'@'127.0.0.1' IDENTIFIED WITH caching_sha2_password BY '${DB_PASSWORD_ROOT}';"
# sudo mysql -e "ALTER USER IF EXISTS 'root'@'::1' IDENTIFIED WITH caching_sha2_password BY '${DB_PASSWORD_ROOT}';"
# sudo mysql -e "CREATE USER IF NOT EXISTS 'root'@'127.0.0.1' IDENTIFIED WITH caching_sha2_password BY '${DB_PASSWORD_ROOT}';"
# sudo mysql -e "CREATE USER IF NOT EXISTS 'root'@'::1' IDENTIFIED WITH caching_sha2_password BY '${DB_PASSWORD_ROOT}';"
# sudo mysql -e "GRANT ALL ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;"
# sudo mysql -e "GRANT ALL ON *.* TO 'root'@'::1' WITH GRANT OPTION;"
## SAFE MODE reset permissions ##
# mkdir /var/run/mysqld
# chown mysql:mysql /var/run/mysqld
# chmod -R 775 /var/run/mysqld
# chown mysql:mysql /var/www/logs/mysql*.log
## copy the default socket for keeps (might disappear during stop MySQL) ##
# cp /var/run/mysqld /var/run/mysqld.bak
## put back socket
# if [ ! -f "/var/run/mysqld/*sock" ]; then
# mv /var/run/mysqld.bak /var/run/mysqld;
# fi
## start the MySQL service again ##
# systemctl unmask mysql.service
# mysqld_safe --init-file=<path to init file>init-file.txt &
# mysqld --init-file=<path to init file>init-file.txt &
# /usr/sbin/mysqld --user=mysql --skip-grant-tables --init-file=/tmp/init-mysql.txt &
# mysqld_safe --skip-grant-tables &
# mysqld --init-file=/tmp/init-mysql.txt &
# rm /tmp/init-mysql.txt*
# wget -O /tmp/init-mysql.txt http://mirrors.slickstack.io/mysql/init-mysql.txt
# sed -i "s/@DB_PASSWORD_ROOT/${DB_PASSWORD_ROOT}/g" /tmp/init-mysql.txt
# chown mysql:mysql /tmp/init-mysql.txt
# chmod 0775 /tmp/init-mysql.txt
## start MySQL without authentication (safe mode) ##
# mysqld --skip-grant-tables --user=mysql &
# bin/mysqld --initialize-insecure --user=mysql
## start MySQL ##
# mysql --skip-password
## grep "A temporary password" /var/log/mysqld.log
## ensure root@localhost uses mysql_native_password ##
#####sudo mysql -e "ALTER USER IF EXISTS 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD_ROOT}';"
#####sudo mysql -e "GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION;"
#####sudo mysql -e "FLUSH PRIVILEGES;"
## reset admin (root alternative) password and make mysql_native_password the default ##
# -u root --skip-password --host="localhost" --protocol=socket --port=3306
# UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'auth_socket';
# mysql -e "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'admin';"
## caching_sha2_password requires TLS, sockets, or shared memory ##
# mysql --flush-privileges -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD_ROOT}';"
# SELECT plugin from mysql.user where User='root';
# SELECT User,plugin from mysql.user where User='root';
# SELECT user,authentication_string,plugin,host FROM mysql.user;
## Ref: https://github.com/littlebizzy/slickstack/issues/23
## Ref: https://stackoverflow.com/questions/36301100/how-do-i-turn-off-the-mysql-password-validation
## Ref: https://dba.stackexchange.com/questions/4614/cannot-drop-anonymous-user-from-mysql-user
## Ref: https://www.networkinghowtos.com/howto/disable-remote-root-logins-into-mysql/
## Ref: https://www.oreilly.com/library/view/mysql-in-a/9780596514334/re39.html
## Ref: https://stackoverflow.com/questions/36463966/when-is-flush-privileges-in-mysql-really-needed
## Ref: https://askubuntu.com/questions/210976/apt-get-remove-with-wildcard-removed-way-more-than-expected-why
## Ref: https://dev.mysql.com/doc/refman/8.0/en/grant.html
## Ref: https://geert.vanderkelen.org/2018/mysql8-unattended-dpkg/
## Ref: https://stackoverflow.com/questions/50177216/how-to-grant-all-privileges-to-root-user-in-mysql-8-0
## Ref: https://www.techiediaries.com/ubuntu/install-mysql-8-ubuntu-20-04/
## Ref: https://kifarunix.com/install-mysql-8-on-ubuntu-20-04/
## Ref: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04
## Ref: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
## Ref: https://dba.stackexchange.com/questions/209514/what-is-mysql-native-password
## Ref: https://linuxconfig.org/how-to-reset-root-mysql-password-on-ubuntu-18-04-bionic-beaver-linux
## Ref: https://askubuntu.com/questions/1242142/mysql-install-error-database-files-are-locked-daemon-already-running-warning
## Ref: https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run
## Ref: https://askubuntu.com/questions/1242142/mysql-install-error-database-files-are-locked-daemon-already-running-warning
## Ref: https://www.digitalocean.com/community/questions/connecting-to-mysql-without-pw-can-t-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2
## Ref: https://serverfault.com/questions/582866/mysql-socket-configuration-issue-in-my-cnf
## Ref: https://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq
## Ref: https://medium.com/@aungzanbaw/how-to-reset-root-user-password-in-mysql-8-0-a5c328d098a8
## Ref: https://stackoverflow.com/questions/49931541/mysql-changing-authentication-type-from-standard-to-caching-sha2-password
## Ref: https://stackoverflow.com/questions/35978228/how-to-solve-innodb-unable-to-lock-ibdata1-mysql-error
## Ref: https://bobcares.com/blog/innodb-unable-to-lock-ibdata1-error-11/
## Ref: https://stackoverflow.com/questions/34954455/mysql-daemon-lock-issue/46779157
## Ref: https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html
## Ref: https://dev.mysql.com/doc/refman/8.0/en/server-options.html
## Ref: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_init_file
## Ref: https://www.pixelstech.net/article/1545701135-How-to-reset-root-password-in-MySQL-8
## Ref: https://stackoverflow.com/questions/61430362/ubuntu-20-04-set-mysql-phpmyadmin-root-password
## Ref: https://www.cloudbooklet.com/how-to-install-mysql-on-ubuntu-20-04/
## Ref: https://www.tecmint.com/reset-root-password-in-mysql-8/
## Ref: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
## Ref: https://serverfault.com/questions/500739/reinstall-mysql-and-keep-existing-database-tables-and-data
## Ref: https://askubuntu.com/questions/643251/having-trouble-installing-and-removing-mysql-in-ubuntu
## Ref: https://stackoverflow.com/questions/21620406/how-do-i-pause-my-shell-script-for-a-second-before-continuing
## Ref: https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781788395809/1/ch01lvl1sec15/starting-or-stopping-mysql-8
## Ref: http://dev.cs.ovgu.de/db/mysql/Common-errors.html
## Ref: https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server
## Ref: https://stackoverflow.com/questions/49194719/authentication-plugin-caching-sha2-password-cannot-be-loaded
## Ref: https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/upgrading-from-previous-series.html
## Ref: https://dev.mysql.com/doc/mysql-secure-deployment-guide/8.0/en/secure-deployment-configure-authentication.html
## Ref: https://phoenixnap.com/kb/access-denied-for-user-root-localhost
## Ref: https://www.sqlshack.com/how-to-install-mysql-on-ubuntu-18-04/
## Ref: https://mysql.tutorials24x7.com/blog/reset-root-password-of-mysql
## Ref: https://phoenixnap.com/kb/how-to-reset-mysql-root-password-windows-linux
## Ref: https://www.oreilly.com/library/view/mysql-8-cookbook/9781788395809/7ea345a8-d753-48cd-a11b-8e6b6a06cacc.xhtml
## Ref: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
## Ref: https://devanswers.co/install-secure-mysql-server-ubuntu-20-04/
## Ref: https://mariadb.com/kb/en/pluggable-authentication-overview/
## Ref: https://dev.mysql.com/doc/refman/8.0/en/connection-options.html
## Ref: https://stackoverflow.com/questions/41846000/mariadb-password-and-unix-socket-authentication-for-root
## Ref: https://www.percona.com/live/e18/sites/default/files/slides/Upgrading%20to%20MySQL%208.0%20and%20a%20More%20Automated%20Experience%20-%20FileId%20-%20159893.pdf
## Ref: https://superuser.com/questions/603026/mysql-how-to-fix-access-denied-for-user-rootlocalhost
## Ref: https://github.com/GoogleCloudPlatform/click-to-deploy/blob/master/vm/chef/cookbooks/mysql8-book/recipes/configure-apt-repo-version-8.0.rb
## Ref: https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
## Ref: https://unix.stackexchange.com/questions/457388/how-to-find-out-the-variable-names-for-debconf-set-selections
## Ref: https://www.codementor.io/@slaith/setting-a-root-password-on-mysql-in-silent-mode-in-ubuntu-y6do6ug2u
## Ref: https://stackoverflow.com/questions/23358918/preconfigure-an-empty-password-for-mysql-via-debconf-set-selections
## Ref: https://forums.mysql.com/read.php?11,666369,666533#msg-666533
## Ref: https://gist.github.com/ziadoz/dc935a0167c68fc23b4f35ee8593125f
## Ref: https://www.reddit.com/r/mysql/comments/3vch8p/uninstall_mysql_via_shell_without_prompt/
## Ref: https://ubuntu.pkgs.org/19.10/ubuntu-main-amd64/mysql-server-8.0_8.0.17-0ubuntu2_amd64.deb.html
## Ref: https://serverfault.com/questions/813210/does-debconf-set-selections-automatically-deletes-values-from-debconf-database-o
## Ref: https://askubuntu.com/questions/399903/unattended-phpmyadmin-install-end-up-throwing-errors
## Ref: https://severalnines.com/database-blog/moving-mysql-57-mysql-80-what-you-should-know
## Ref: https://medium.com/@benmorel/remove-the-mysql-root-password-ba3fcbe29870
## Ref: https://dev.mysql.com/doc/refman/8.0/en/validate-password-installation.html
## Ref: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
## Ref: https://vander.host/knowledgebase/databases/cant-login-as-root-to-phpmyadmin-on-new-server-install/
## Ref: https://devanswers.co/phpmyadmin-access-denied-for-user-root-localhost/
## Ref:https://serverfault.com/questions/906490/mysql-rejects-connections-with-auth-socket
## Ref: https://bugs.mysql.com/bug.php?id=79269
## Ref: https://php.watch/articles/PHP-7.4-MySQL-8-server-gone-away-fix
## Ref: https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost
## Ref: https://stackoverflow.com/questions/52364415/php-with-mysql-8-0-error-the-server-requested-authentication-method-unknown-to
## Ref: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04-quickstart
## Ref: https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
## Ref: https://www.percona.com/blog/2019/11/01/use-mysql-without-a-password/
## Ref: https://gist.github.com/jessuppi/ab5517aa50b3bc83ac37abb8267e005b
## Ref: https://dev.mysql.com/doc/refman/8.0/en/option-file-options.html
## Ref: https://docs.oracle.com/cd/E17952_01/mysql-5.6-en/mysqld-safe.html
## Ref: http://doc.mawan.de/dictionaries-common/README.problems
## Ref: https://askubuntu.com/questions/429512/dpkg-or-something-related-is-corrupted
## Ref: https://www.digitalocean.com/community/tutorials/how-to-configure-ssl-tls-for-mysql-on-ubuntu-18-04
## Ref: https://dev.mysql.com/doc/refman/8.0/en/encrypted-connections.html
## SS_EOF