DRgrtea

Medsos DRcjgrTeA

Media Sosial Duridwangurunatafkar

Alih Bahasa

English French German Spain Italian Dutch Russian Brazil Japanese Korean Arabic Chinese Simplified

DRMenuNavigasiBar

menunavngampar

Senin, 27 Januari 2025

drKoding | MySQL | Nginstal

 

1. 
2.a
2.b >>> complete
3.
4.
5.a
5.b
6.a
6.b
Konfigurasi
7.
8.
9.
Penggunaan Database
10. 
11. 
12.


13.

14
15
Durid1@7341 - DRcjgTeA - 

16

18

=====================================================

=====================================================

MySQL Cheat Sheet

Help with SQL commands to interact with a MySQL database

MySQL Locations

  • Mac /usr/local/mysql/bin
  • Windows /Program Files/MySQL/MySQL version/bin
  • Xampp /xampp/mysql/bin

Add mysql to your PATH

# Current Session
export PATH=${PATH}:/usr/local/mysql/bin
# Permanantly
echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.bash_profile

On Windows - https://www.qualitestgroup.com/resources/knowledge-center/how-to-guide/add-mysql-path-windows/

Login

mysql -u root -p

Show Users

SELECT User, Host FROM mysql.user;

Create User

CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'somepassword';

Grant All Priveleges On All Databases

GRANT ALL PRIVILEGES ON * . * TO 'someuser'@'localhost';
FLUSH PRIVILEGES;

Show Grants

SHOW GRANTS FOR 'someuser'@'localhost';

Remove Grants

REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'someuser'@'localhost';

Delete User

DROP USER 'someuser'@'localhost';

Exit

exit;

Show Databases

SHOW DATABASES

Create Database

CREATE DATABASE acme;

Delete Database

DROP DATABASE acme;

Select Database

USE acme;

Create Table

CREATE TABLE users(
id INT AUTO_INCREMENT,
   first_name VARCHAR(100),
   last_name VARCHAR(100),
   email VARCHAR(50),
   password VARCHAR(20),
   location VARCHAR(100),
   dept VARCHAR(100),
   is_admin TINYINT(1),
   register_date DATETIME,
   PRIMARY KEY(id)
);

Delete / Drop Table

DROP TABLE tablename;

Show Tables

SHOW TABLES;

Insert Row / Record

INSERT INTO users (first_name, last_name, email, password, location, dept, is_admin, register_date) values ('Brad', 'Traversy', 'brad@gmail.com', '123456','Massachusetts', 'development', 1, now());

Insert Multiple Rows

INSERT INTO users (first_name, last_name, email, password, location, dept,  is_admin, register_date) values ('Fred', 'Smith', 'fred@gmail.com', '123456', 'New York', 'design', 0, now()), ('Sara', 'Watson', 'sara@gmail.com', '123456', 'New York', 'design', 0, now()),('Will', 'Jackson', 'will@yahoo.com', '123456', 'Rhode Island', 'development', 1, now()),('Paula', 'Johnson', 'paula@yahoo.com', '123456', 'Massachusetts', 'sales', 0, now()),('Tom', 'Spears', 'tom@yahoo.com', '123456', 'Massachusetts', 'sales', 0, now());

Select

SELECT * FROM users;
SELECT first_name, last_name FROM users;

Where Clause

SELECT * FROM users WHERE location='Massachusetts';
SELECT * FROM users WHERE location='Massachusetts' AND dept='sales';
SELECT * FROM users WHERE is_admin = 1;
SELECT * FROM users WHERE is_admin > 0;

Delete Row

DELETE FROM users WHERE id = 6;

Update Row

UPDATE users SET email = 'freddy@gmail.com' WHERE id = 2;

Add New Column

ALTER TABLE users ADD age VARCHAR(3);

Modify Column

ALTER TABLE users MODIFY COLUMN age INT(3);

Order By (Sort)

SELECT * FROM users ORDER BY last_name ASC;
SELECT * FROM users ORDER BY last_name DESC;

Concatenate Columns

SELECT CONCAT(first_name, ' ', last_name) AS 'Name', dept FROM users;

Select Distinct Rows

SELECT DISTINCT location FROM users;

Between (Select Range)

SELECT * FROM users WHERE age BETWEEN 20 AND 25;

Like (Searching)

SELECT * FROM users WHERE dept LIKE 'd%';
SELECT * FROM users WHERE dept LIKE 'dev%';
SELECT * FROM users WHERE dept LIKE '%t';
SELECT * FROM users WHERE dept LIKE '%e%';

Not Like

SELECT * FROM users WHERE dept NOT LIKE 'd%';

IN

SELECT * FROM users WHERE dept IN ('design', 'sales');

Create & Remove Index

CREATE INDEX LIndex On users(location);
DROP INDEX LIndex ON users;

New Table With Foreign Key (Posts)

CREATE TABLE posts(
id INT AUTO_INCREMENT,
   user_id INT,
   title VARCHAR(100),
   body TEXT,
   publish_date DATETIME DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY(id),
   FOREIGN KEY (user_id) REFERENCES users(id)
);

Add Data to Posts Table

INSERT INTO posts(user_id, title, body) VALUES (1, 'Post One', 'This is post one'),(3, 'Post Two', 'This is post two'),(1, 'Post Three', 'This is post three'),(2, 'Post Four', 'This is post four'),(5, 'Post Five', 'This is post five'),(4, 'Post Six', 'This is post six'),(2, 'Post Seven', 'This is post seven'),(1, 'Post Eight', 'This is post eight'),(3, 'Post Nine', 'This is post none'),(4, 'Post Ten', 'This is post ten');

INNER JOIN

SELECT
  users.first_name,
  users.last_name,
  posts.title,
  posts.publish_date
FROM users
INNER JOIN posts
ON users.id = posts.user_id
ORDER BY posts.title;

New Table With 2 Foriegn Keys

CREATE TABLE comments(
	id INT AUTO_INCREMENT,
    post_id INT,
    user_id INT,
    body TEXT,
    publish_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY(id),
    FOREIGN KEY(user_id) references users(id),
    FOREIGN KEY(post_id) references posts(id)
);

Add Data to Comments Table

INSERT INTO comments(post_id, user_id, body) VALUES (1, 3, 'This is comment one'),(2, 1, 'This is comment two'),(5, 3, 'This is comment three'),(2, 4, 'This is comment four'),(1, 2, 'This is comment five'),(3, 1, 'This is comment six'),(3, 2, 'This is comment six'),(5, 4, 'This is comment seven'),(2, 3, 'This is comment seven');

Left Join

SELECT
comments.body,
posts.title
FROM comments
LEFT JOIN posts ON posts.id = comments.post_id
ORDER BY posts.title;

Join Multiple Tables

SELECT
comments.body,
posts.title,
users.first_name,
users.last_name
FROM comments
INNER JOIN posts on posts.id = comments.post_id
INNER JOIN users on users.id = comments.user_id
ORDER BY posts.title;

Aggregate Functions

SELECT COUNT(id) FROM users;
SELECT MAX(age) FROM users;
SELECT MIN(age) FROM users;
SELECT SUM(age) FROM users;
SELECT UCASE(first_name), LCASE(last_name) FROM users;

Group By

SELECT age, COUNT(age) FROM users GROUP BY age;
SELECT age, COUNT(age) FROM users WHERE age > 20 GROUP BY age;
SELECT age, COUNT(age) FROM users GROUP BY age HAVING count(age) >=2;

Tidak ada komentar:

Posting Komentar

Posting Populer

Duridwan TeA Google Arsip

Tampil Ful Skrin

Tampilan penuh layar

Klik tombol "Penuh" untuk mode ful skrin. Tutup dengan cara klik tuts "Esc" di kibot, atau dengan mengklik tombol "Normal" saja.

Penuh Normal

Materi artikel

DRLabel

'Urwah ۝۞ دعاء الأوراد ۞۝ 1drive 2019 3Dwarehouse Abaib Academia AdminisGuru Adzan AKGTK Akrab 9497 AkselelatorDRc Aksioma Alfa Aljamal Anakku Android Apache API Aplikasi Aplikasi Online Aplikasiku aqidah aqo'id Arsiper Arudl ASPnet Atribusi Attaqwa Audacity Audio Aurod AutoCAD ba'da sholat Ba'diyah Babad Bahasa Indonesia Balaghoh Baleomol Banner basund Belajar.id Biantara bilibiliTV bing.com Biografi Bisikan Bisnis Blog blogku Bluestack BMTT Bola Dunia Boxmode BUKU C++ Caknun Canva Capcut CData Cerita Chanel Cijagong Copast Coreldraw;Koreldrow cortang CPANEL cv Daftar Isi Daftar Tamu Dailymotion Dakwah Daring db515TB Dek@t Dikdasmen Diktat Do''a Domainesia dongeng Download DRctvone DRcVivaTV DRlink drSoftaculous Duridwancijag duridwanMI E-Book Earth eDGe Edmodo Edwin ekstensi Emulated Epson eSDeKU Excel Facebook Fafa Belajar favicon FB FBwatch Fikih Film FKGN FKSS Flickr ftf ftp Gambar Gaweku GDexcel GDrive GDword Gif Giphy Github Goguru googele Gosiswawi GS v2 Gudang Gif GuMeng Guru Hotmail HP HUDHUD ATTWITERI humor iframe IHTT IIS IKBAL ikonku Ilham Ilmu Waris Imam Mahdi Iman imrithi imtihan Inlislite ips Ips siswa irkhash Ishol Israel Jackie Chan JadwalHirup Jendelatea Jurumiah Kaamengan Kaldik karuhun Kasintu Kasyif Kemdak Kenangan Kepesantrenan KHMZ Khutbah Idul Adha Khutbah Jum'at Kitab Koneng KlaudiAwan KMS KodeBlok Koding Komentarku konsorsium Kristen KSM KSM_24 kulsub Kumer Kutab Kuning Lalogin Laporan link lirik sunda Literasi LKSATA Logo Lokasi LTNU Malaikat Mama Gelar mapel Mapel Plus marawis materi ajar materi ips materi sunda Mediafire Menu Mulai Messenger meta Metode Belajar MGMP MTS Mi.co.id Microsoft Mikrosoft Word MKKS MKSS MKT Modul MoU Movie MTs. Mushaf Sunda Mvs Nabi nadhom nahwu Nashoih Nasihat Pernikahan Nasrudin Hoja Nasyid NewTabTvSearch Ngablog ngaDOS Ngaji Pontren Nganet Ngaos ngaweb Ngimel Ngobrol Solat ngobrolgurutea ngoding Ngoleksi Nikah Nonton Nubuwwah NUPTKku Nyekrip Nyitus OderPejKu Office office 2010 Office.co.id Offidocs ome Ome.TV omeaeun Onedrive Opis OpisTeA Oracle OSIS Outlook Pakakas Pamilarian PaperDropboxTeA PAS PAS S1 PAT pdf Penahexa Penilaian Perangkat Guru Peringatan Nabi perpus Perpusdig PHBI photo Phyton Pintarkem PKKM PKKS PKSS PohonKeluarga Ponpes Portabel Post WA PPDB PPKKS Prkt Ltk Program Files Proker Proposal Prosem Prota PTS PTS S1 publikteaqta Pupujian Quran Sunda Rapat RDM Removal renungan RFC RidsyafTeA Risalah Risalah Sholat RKS Rohbiyah Romadlon Romadon Rumus Rumus;PHP; RumusHead s.idku Safari Santif Sanusi segitiga Sekolah seren tampi Sertifikat sholat Shopee Shorof sifat_20 Silaturahmi Simdif SIMPATIKA sinopsis siswa sitegog Skenario Belajar Sketchup SketsaupTeA Slayid SMA Soal Soanten Software SoraTeuPerluNinggal StoryTelling Suara Sukapura sumputkeun sunda syare'at Ta'lim tabir mimpi Tadabbur tadarrus TafkarMart Tahajud Tahlil Tasbeh Taskbar Tauhid Tawasul Tema Blog tenor.com Terjemah tiktok TimTeA tips n trick Trik Tsaqifah tulisan TV Nasional Twitter Usaha Vektor Video Video Player Video;Edit Video;Rara VideoPost vidio w3s WA - AYT wahyu Wali Walimahan Wallpaper wayang WeA Windows Wirid Witir word Wordpress WordTeA WorldBank WP WPS WS XLS DRcjgTeA Yahoo yandexck Yapista link YT ytDuridwanSunda YTstudio Yutub ZIP Zoom سلاح الدعوة
×
Judul