Difference between revisions of "MySQL"
Jump to navigation
Jump to search
(Created page with "===Perintah=== ====Login==== mysql -u <username> -p Kemudian isikan passwordnya ====Melihat database yang ada==== show databases; ====Membuat database==== CR...") |
|||
Line 67: | Line 67: | ||
mysql -u <username> -p <nama-database> < db.sql | mysql -u <username> -p <nama-database> < db.sql | ||
+ | |||
+ | |||
+ | ====GRANT ALL==== | ||
+ | |||
+ | create user 'user' identified by 'password'; | ||
+ | grant all privileges on database-name.* to 'user'; |
Revision as of 13:44, 7 January 2022
Contents
Perintah
Login
mysql -u <username> -p
Kemudian isikan passwordnya
Melihat database yang ada
show databases;
Membuat database
CREATE DATABASE <nama_database>;
Drop database
DROP DATABASE <nama_database>;
Melihat tabel yang ada
show tables;
Membuat tabel
CREATE TABLE Mahasiswa ( NPM int(11) PRIMARY KEY, Nama varchar(255) NOT NULL );
Jika ID autoincrement
CREATE TABLE Barang ( Barangid int NOT NULL AUTO_INCREMENT, NamaBarang varchar(255) NOT NULL, PRIMARY KEY (Barangid) );
Modifikasi tabel
ALTER TABLE Mahasiswa ADD Email varchar(255); ALTER TABLE Mahasiswa DROP COLUMN Email; ALTER TABLE <table_name> MODIFY COLUMN <column_name> <datatype>;
Insert data
INSERT INTO Mahasiswa (NPM, Nama) VALUES ('001', 'Mahasiswa 1'), ('002', 'Mahasiswa 2');
Export sql
mysqldump -u <username> -p <nama-database> > db.sql
Import sql
mysql -u <username> -p <nama-database> < db.sql
GRANT ALL
create user 'user' identified by 'password'; grant all privileges on database-name.* to 'user';