Skip to content
Luke Chen edited this page May 21, 2021 · 7 revisions

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04

sudo mysql_secure_installation

password validation policy: LOW Length >= 8

sudo mysql -u root -p 
# or
sudo mysql

mysql> CREATE USER 'mysqluser1'@'localhost' IDENTIFIED BY 'xxxxxxxx';
ALTER USER 'mysqluser1'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxxxxx';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxxx';

mysql> REVOKE ALL on *.* FROM 'mysqluser1'@'localhost';
mysql> GRANT CREATE, CREATE VIEW, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'mysqluser1'@'localhost' WITH GRANT OPTION;
mysql> GRANT ALL on *.* TO 'mysqluser1'@'localhost' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

mysql -u mysqluser1 -p

show databases;
use mysql # use my db
show tables;


$ sudo mysqladmin -p -u mysqluser1 version
Enter password: 
mysqladmin  Ver 8.0.22-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version		8.0.22-0ubuntu0.20.04.3
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			25 min 7 sec

Threads: 2  Questions: 35  Slow queries: 0  Opens: 130  Flush tables: 3  Open tables: 51  Queries per second avg: 0.023
$ mysql -u mysqluser1 -p
Enter password: testtest1

MySQL sample db https://dev.mysql.com/doc/employee/en/employees-installation.html

MySQL python connector https://dev.mysql.com/downloads/connector/python/ https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html

My examples: https://github.com/lukechendev/purecoding/blob/master/workspace_systemdesign/memcached/a01_query_employees.py

Clone this wiki locally