Python Flask-MySQL LAB
Follow the video tutorials:
Instalacion Python Flask+MySQL (To use pip3 please follow commands below):
https://www.youtube.com/watch?v=CX7eoK7Ku8M
Formulario Registro de Usuarios en Python Flask – Parte 1:
https://www.youtube.com/watch?v=7Oj4LcCE7n8
Formulario Registro de Usuarios en Python Flask – Parte 2:
https://www.youtube.com/watch?v=L20z4gCSfA8
Formulario para login de Usuarios en Python Flask:
https://www.youtube.com/watch?v=bdkIQsJQvNQ
To Install Flask using pip3:
sudo yum install epel-release
sudo yum install python3-pip
pip3 –version
sudo pip3 install Flask
pip3 freeze | grep Flask
To Install MySQL and libraries:
sudo yum update
sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
sudo yum install mysql-server
sudo systemctl start mysqld
sudo systemctl status mysqld
MySQL + Flask Support
sudo yum install mysql-devel
sudo yum install python3-devel
sudo yum install gcc
sudo pip3 install flask-mysqldb
Change MySQL Password
Try $ mysql -u root –p
with no password, if this doesn't work, try with the random passw:
Look for the random password in the server error log.
[vagrant@servidorFlask ~]$ sudo cat /var/log/mysql/mysqld.log
2020-04-28T02:54:17.993865Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld
8.0.20) initializing of server in progress as process 12545
2020-04-28T02:54:18.019986Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has
started.
2020-04-28T02:54:19.896409Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has
ended.
2020-04-28T02:54:21.978120Z 6 [Note] [MY-010454] [Server] A temporary password is
generated for root@localhost: :oww-ek<J0ql
Connect to mysql using the random password generated in your installation
$ mysql -u root –p
Enter password: :oww-ek<J0ql (for example)
Replace the random password for Autonoma123*
$ mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Autonoma123*';
Install Form Tools
sudo pip3 install Flask-WTF
sudo pip3 install passlib
Exercise
1. Add the following functionality:
Add Article
Edit Article
Delete Article
2. Administració n de bases de datos con MySQLWorkbench
Instale MySQLWorkbench
Disponible en https://www.mysql.com/products/workbench/
Conéctese al servidor mysql instalado. Para esto necesitara crear un nuevo
usuario en el servidor con privilegios
mysql -u root -p
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT
OPTION;
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
service mysqld restart
Busque tutoriales de MySQLWorkbench. Por ejemplo puede serguir el
siguiente tutorial de YouTube:
https://www.youtube.com/watch?v=heorENnhXYw
Para la creació n y administració n de una base de datos.
References
• Flask: http://flask.pocoo.org/
• Getting Started With Flask: https://scotch.io/tutorials/getting-started-with-
flask-a-python-microframework#toc-file-structure
• Instal MySQL: https://www.linode.com/docs/databases/mysql/how-to-
install-mysql-on-centos-7/
• Python Flask from Scratch: https://www.youtube.com/watch?
v=zRwy8gtgJ1A&t=1239s
• MySQL Workbench
https://www.mysql.com/products/workbench/