Sharing local MySQL using SSH Part 2
Prerequisite:
✓ Completed Part 1 (Setting up SSH)
For part 2 gagawa naman tayo ng mysql user na gagamitin ng ka grupo mo para ma access yung local mysql mo un
ung gagamitin mo den sa .env ng Laravel (eto yung sinasabi ni sir Mel last time).
1. Create a mysql User
Open MySQL and type the following commands:
▪ CREATE USER '<user>'@'%' IDENTIFIED BY '<password>';
▪ GRANT ALL PRIVILEGES ON <database>.* TO '<user>'@'%';
▪ FLUSH PRIVILEGES;
You can edit the privileges sa gagawin niong user refer to this table:
Database-Level Privileges:
What it Allows
Privilege
Read data from tables
SELECT
Add new rows
INSERT
Modify existing rows
UPDATE
Remove rows
DELETE
Create new databases or tables
CREATE
Delete databases or tables
DROP
Create or drop indexes
INDEX
Change table structure
ALTER
Give this user privileges to others
GRANT OPTION
What it Allows
Privilege
Administrative tasks (shutdown
SUPER server, kill threads)
Administrative Privileges:
What it Allows
Privilege
See running queries by other
PROCESS users
Reload privileges or flush logs
RELOAD
Read/write files on the server
FILE
SHOW List all databases
DATABASES
CREATE Create temp tables in memory
TEMPORARY
TABLES
Lock tables for transactions
LOCK TABLES
Create and manage scheduled
EVENT events
Create and manage triggers
TRIGGER
Example:
• Read-only user:
GRANT SELECT ON dorm.* TO 'readonly'@'%';
• Data-entry user:
GRANT SELECT, INSERT, UPDATE, DELETE ON dorm.* TO 'datauser'@'%';
• Full access user (lahat):
GRANT ALL PRIVILEGES ON dorm.* TO 'marc'@'%';
Full access nio nlng HAHHAHHA
2. Connect to the server
Open SSH tunnel first
ssh -L 3307:[Link]:3306 -o ServerAliveInterval=60
<username>@<server_ip>
Run this on your laptop (the one connecting). Keep this open, this is your connection to the other
devices mysql (do not close it while using mysql)
What this does is basically forwarding computer 1 sql (localhost:3306) and using it in computer 2
as port 3307
3. Use the created mysql user
Type the command and enter the password
mysql -h [Link] -P 3307 -u <username> -p
4. Connect to Laravel
Edit the .env file to use the created user
php artisan config:clear
after editing .env file
DONEEEE