user-img
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/mysql 17
[Ubuntu] mysql ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰, ์ง‘๊ณ„, ์กฐ์ธ
select๋ฌธ select ์†์„ฑ, ์†์„ฑ... from ํ…Œ์ด๋ธ”๋ช… where ๊ฒ€์ƒ‰ ์กฐ๊ฑด(>= / between(๋ฒ”์œ„) / in, not in(10000, 20000) / like '์–ด์ฉŒ๊ตฌ' / is null, is not null / and, or, not) group by ์†์„ฑ๋ช… having ๊ฒ€์ƒ‰์กฐ๊ฑด order by ์†์„ฑ๋ช… asc/desc (์˜ค๋ฆ„์ฐจ์ˆœ/๋‚ด๋ฆผ์ฐจ์ˆœ) ์‚ฌ์šฉ ์•ˆ ํ•œ๋‹ค๋ฉด ๊ทธ๋ƒฅ ์†์„ฑ๋ช… ์ˆœ์œผ๋กœ ๋‚˜์˜ด. ๊ฒ€์ƒ‰ ์กฐ๊ฑด์€ ๊ด„ํ˜ธ์—์„œ์™€ ๊ฐ™์ด ์ด๋Ÿฐ ์‹์œผ๋กœ ์ž‘์„ฑ ๊ฐ€๋Šฅ where price between 1000 and 2000 price >= 1 and price
2023.12.04
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/mysql
thumbnail
[Ubuntu] mysql ์กฐ์ธ(์ด๋„ˆ/์•„์šฐํ„ฐ) ์˜ˆ์ œ
1. ์ฑ…์„ ์ฃผ๋ฌธํ•œ ๊ณ ๊ฐ์ •๋ณด์™€ ์ฃผ๋ฌธ์ •๋ณด select * from cust, orders where cust.cid = orders.cid; 2. ์ฃผ๋ฌธ๋œ ์ฑ…์˜ ์ •๋ณด์™€ ์ฃผ๋ฌธ์ •๋ณด select * from book, orders whrer book.bid = orders.bid; 3. ์ฃผ๋ฌธ์ •๋ณด๋ฅผ ๋ณด์ด๊ธฐ(oid, cname, title, price) select oid, cname, title, price from cust, orders, book where cust.cid = orders.cid and book.bid = orders.bid; 4. ๊ณ ๊ฐ์˜ ์ฃผ๋ฌธ์ •๋ณด ๋ณด์ด๊ธฐ ๋‹จ, ์ด๋ฆ„์ˆœ์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœํ•ด์„œ(oid, cname) select oid, cname from cust inner join orders on cus..
2023.12.04
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/mysql
[Ubuntu] ์šฐ๋ถ„ํˆฌ ๊ธฐ์ค€ mysql ๊ธฐ๋ณธ ๋ช…๋ น
๊ธฐ๋ณธ ๋ช…๋ น์— ๊ด€ํ•ด์„œ ์ •๋ฆฌ mysql -p //์‹คํ–‰, ํ›„ ๋น„๋ฒˆ ์ž…๋ ฅ(์„ค์ • ์•ˆํ–ˆ๋‹ค๋ฉด ๊ทธ๋ƒฅ ์—”ํ„ฐ) \q //์ข…๋ฃŒ use ๋””๋น„๋ช…; //๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ ํƒ show databases; //๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ณด๊ธฐ create database ๋””๋น„๋ช…; //๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ drop database ๋””๋น„๋ช…; //๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‚ญ์ œ create table ํ…Œ์ด๋ธ”๋ช…( //ํ…Œ์ด๋ธ” ์ƒ์„ฑ ์ด๋ฆ„ int primary key, ์ด๋ฆ„ varchar(20), ์ด๋ฆ„ int); show tables; //ํ…Œ์ด๋ธ” ๋ณด๊ธฐ select * from ํ…Œ์ด๋ธ”๋ช…; //ํ…Œ์ด๋ธ”์˜ ๋ชจ๋“  ๊ฒƒ ๋ณด๊ธฐ(*์— ๋ณด๊ณ  ์‹ถ์€ ๊ฑธ ์ž…๋ ฅํ•˜๋ฉด ๊ทธ๊ฒƒ์ด ๋œจ๊ฒ ์ฃ . show create table ํ…Œ์ด๋ธ”๋ช…; //ํ…Œ์ด๋ธ” ์กฐ๊ฑด ๋ณด๊ธฐ explain ํ…Œ์ด๋ธ”๋ช…; //ํ…Œ์ด๋ธ” ๊ตฌ์กฐ ๋ณด๊ธฐ set fore..
2023.12.04
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/mysql
thumbnail
[Ubuntu] ์šฐ๋ถ„ํˆฌ mysql ๊ธฐ๋ณธ ์ดˆ๊ธฐ ์„ค์ •
์ผ๋‹จ ์‹คํ–‰ํ•ด์„œ su๋กœ ๋ฃจํŠธ ๊ณ„์ •์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ์‹œ๋‹ค(๋น„๋ฒˆ ๊ธฐ์–ต ์•ˆ ๋‚œ๋‹ค๋ฉด sudo passwd root ํ•ด์„œ ๋น„๋ฒˆ ์„ค์ •ํ•˜์‹ญ์‹œ์˜ค) mysql ์„ค์น˜ sudo apt-get install mysql-server ํ•œ์ฐธ ๊ธฐ๋‹ค๋ฆฌ๋ฉด ์„ค์น˜๊ฐ€ ๋‹ค ๋ฉ๋‹ˆ๋‹ค ์‹คํ–‰ํ•˜๋Š” ๋ฒ• mysql -p ๋น„๋ฒˆ ์ž…๋ ฅํ•˜๋ผ๋Š”๋ฐ ์ฒ˜์Œ ์‹คํ–‰ํ–ˆ์œผ๋ฉด ๋น„๋ฒˆ์ด ์—†๊ธฐ์— ๊ทธ๋ƒฅ ์—”ํ„ฐ์น˜๋ฉด ๋ฉ๋‹ˆ๋‹ค ์ผ์ผ€ ์‹คํ–‰๋๋‹ค๋ฉด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•ด๋ด…์‹œ๋‹ค. alter user ์œ ์ €์ด๋ฆ„@localhost identified by ‘๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋ ฅ’; ์œ ์ €์ด๋ฆ„์€ root๋กœ ์ ‘์†ํ–ˆ๋‹ค๋ฉด root, ๋‹ค๋ฅธ ๊ณ„์ •์œผ๋กœ ์ ‘์†ํ–ˆ๋‹ค๋ฉด ๊ทธ ๊ณ„์ •๋ช… ์ ์–ด์ฃผ์‹ฌ ๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์‹์œผ๋กœ ๊ธฐ๋ณธ ์‚ฌ์šฉ์„ ํ•ด๋ด…์‹œ๋‹ค create database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…;##๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ create user ์œ ์ €๋ช…@localhost ident..
2023.12.04
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/mysql
ERROR 2002 (HY000) : Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
https://shifeed.tistory.com/entry/%EC%9A%B0%EB%B6%84%ED%88%AC%EC%97%90%EC%84%9C-mysqlsock%EB%A5%BC-%EC%B0%BE%EC%9D%84-%EC%88%98-%EC%97%86%EB%8B%A4%EA%B3%A0-%EB%82%98%EC%98%AC%EB%95%8C ์šฐ๋ถ„ํˆฌ์—์„œ mysql.sock๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ  ๋‚˜์˜ฌ๋•Œ. sudo find / -type s | grep mysqld.sock ๋กœ ์ฐพ์•„๋ด๋„ mysqld๊ฐ€ ์—†๋‹ค๊ณ  ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. sudo mkdir -p /var/run/mysqld sudo chown mysql /var/run/mysqld/ sudo service mysql restart ์œ„์˜ ๋ช…๋ น์–ด๋กœ ์‹คํ–‰ํ•˜๋ฉด mysql์„ ์‹ค..
2023.12.04
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/mysql