% mysql -u root -p
show databases;
create database testdb;
use testdb;
drop database testdb;
create database mydb;
show databases;
drop database mydb;
show databases;
use mysql;
select host, user from user;
create user 'usename'@'localhost' identified by 'password';
create user 'lee'@'localhost' identified by '1234';
create user 'usename'@'%' identified by 'password';
create user 'lee'@'%' identified by '5678';
drop user 'lee'@'localhost';
drop user 'lee'@'%';
create user 'zero'@'%' identified by '1234';
drop user 'zero'@'%';
select host, user from user;
create database testdb;
show databases;
create user 'lee'@'localhost' identified by '1234';
select host, user from user;
show grants for 'username'@'localhost';
show grants for 'lee'@'localhost';
grant all on dbname.* to 'username'@'localhost';
grant all on testdb.* to 'lee'@'localhost';
show grants for 'lee'@'localhost';
revoke all on dbname.* from 'username'@'localhost';
revoke all on testdb.* from 'lee'@'localhost';
show grants for 'lee'@'localhost';
flush privileges;
create database mydb;
create user 'zero'@'localhost' identified by '1234';
show grants for 'zero'@'localhost';
grant all on mydb.* to 'zero'@'localhost';
show grants for 'zero'@'localhost';
revoke all on mydb.* from 'lee'@'localhost';
show grants for 'zero'@'localhost';
drop user 'zero'@'localhost';
drop database mydb;
create database zerobase default character set utf8mb4;
show databases;
Table : 데이터베이스 안에서 실제 데이터가 저장되는 행태, 행(Row)과 열(Column)으로 구성된 데이터 모음
Table 생성 문법
create table tablename
(
columnname datatype,
columnname datatype,
...
)
create table mytable(id int, name varchar(16));
use zerobase;
create table mytable ( id int, name varchar(16) );
show tables;
desc tablename;
desc mytable;
create database testdb;
use testdb;
create table animal(name varchar(16), type varchar(16));
show tables;
desc animal;
drop database testdb;
alter table tablename
rename new_tablename
use zerobase;
alter table mytable rename person;
show tables;
alter table tablename
add column columnname datatype;
alter table tablename
modify column columnname datatype;
alter table person modify column agee int;
desc person;
alter table tablename
change column old_columnname new_columnname new_datatype;
alter table person change column agee age int;
desc person;
alter table tablename
drop column columnname;
alter table person drop column age;
desc person;
drop table tablename;
drop table person;
show tables;
create database testdb;
show databases;
create table animal(name varchar(16), type varchar(16));
show tables;
desc animal;
alter table animal add column age int;
desc animal;
alter table animal add column old int;
desc animal;
alter table animal drop column age;
desc animal;
alter table animal change column old sex char;
desc animal;
drop table animal;
show tables;
💻 출처 : 제로베이스 데이터 취업 스쿨