PYTHON
# Create virtual environment
python -m venv mysql-database
# enter to virtual environment folder
cd mysql-database
# activate virEnv
.\\Scripts\\activate
''' if you see cannot be loaded because running scripts is disabled on this system'''
set-executionpolicy remotesigned # use this command in administrator prompt '''
# Installing mysql-connector-python and sqlAlchemy
pip install mysql-connector-python
pip install sqlalchemy
SQL
# enter to mysql
mysql -u root -p
# create database called projects
CREATE DATABASE projects;
# enter to database
use projects;
# Create table
CREATE TABLE projects(project_id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(30),
description VARCHAR(255),
PRIMARY KEY(project_id));
# showing tables
show tables;
# Create table using foreign key of projects
CREATE TABLE tasks(task_id INT(11) NOT NULL AUTO_INCREMENT,
project_id INT(11) NOT NULL,
description VARCHAR(255),
PRIMARY KEY(task_id),
FOREIGN KEY(project_id) REFERENCES projects(project_id));
# Insert value
INSERT INTO projects(title, description)
VALUES ("Organize Photos", "Organize old iPhone photos by year");
INSERT INTO tasks(description, project_id) VALUES ("Organize 2020 Photos", 1);
TERMINAL COMMANDS
sudo systemctl stop mysql
sudo systemctl start mysql
sudo systemctl status mysql
# Login as root
sudo mysql -u root
# Create password (example password: Secret1.)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Secret1.';
mysql> CREATE USER 'sg'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Secret1.';
# Connect (You must use the -p flag with the mysql client=
mysql -u root -P 3307 -p
Change Password
# Change root password
mysql -h <hostname> -u root -p"<old_password>" -P <port> -e "ALTER USER 'root'@'%' IDENTIFIED BY '<new_password>'; ALTER USER 'root'@'[localhost](<http://localhost>)' IDENTIFIED BY '<new_password>';"
# Change another user's password (using new root password)
mysql -h <hostname> -u root -p<new_root_password> -P <port> -e "ALTER USER '<username>'@'%' IDENTIFIED BY '<new_password>'; FLUSH PRIVILEGES;"
# Examples:
# - Replace <hostname> with your host (e.g., [localhost](<http://localhost>) or remote host)
# - Replace <port> with your port (default: 3306)
# - Replace <old_password> and <new_password> with actual passwords
# - Replace <username> with the user to modify
# - Note: No space between -p and password when using inline format
Export DB
mysqldump
-h 127.0.0.1
-u root
-p"Secret1."
--port=3306
--set-gtid-purged=OFF
--complete-insert
--extended-insert
--hex-blob
facturation_manager > facturation_manager_FINAL.sql