"Bash에서 MySQL 사용"의 두 판 사이의 차이

67번째 줄: 67번째 줄:
.. (생략)
.. (생략)
user
user
</source>
==출력형태==
;표(--table, -t, 기본값)
<source lang='dos'>
[root@jmnote ~]# mysql -uroot -pP@ssw0rd -e 'SHOW PROCESSLIST;'
+--------+------+-----------+------+---------+------+-------+------------------+
| Id    | User | Host      | db  | Command | Time | State | Info            |
+--------+------+-----------+------+---------+------+-------+------------------+
| 345227 | root | localhost | NULL | Query  |    0 | NULL  | SHOW PROCESSLIST |
+--------+------+-----------+------+---------+------+-------+------------------+
</source>
;배치(--batch, -B)
<source lang='dos'>
[root@jmnote ~]# mysql -uroot -pP@ssw0rd -e 'SHOW PROCESSLIST;' -B
Id User Host db Command Time State Info
345224 root localhost NULL Query 0 NULL SHOW PROCESSLIST
</source>
;html(--html, -H)
<source lang='dos'>
[root@jmnote ~]# mysql -uroot -pP@ssw0rd -e 'SHOW PROCESSLIST;' -H
<TABLE BORDER=1><TR><TH>Id</TH><TH>User</TH><TH>Host</TH><TH>db</TH><TH>Command</TH><TH>Time</TH><TH>State</TH><TH>Info</TH></TR><TR><TD>345240</TD><TD>root</TD><TD>localhost</TD><TD>NULL</TD><TD>Query</TD><TD>0</TD><TD>NULL</TD><TD>SHOW PROCESSLIST</TD></TR></TABLE>
</source>
;XML(--xml, -X)
<source lang='dos'>
[root@jmnote ~]# mysql -uroot -pP@ssw0rd -e 'SHOW PROCESSLIST;' -X
<?xml version="1.0"?>
<resultset statement="SHOW PROCESSLIST" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
<field name="Id">345242</field>
<field name="User">root</field>
<field name="Host">localhost</field>
<field name="db" xsi:nil="true" />
<field name="Command">Query</field>
<field name="Time">0</field>
<field name="State" xsi:nil="true" />
<field name="Info">SHOW PROCESSLIST</field>
  </row>
</resultset>
</source>
</source>


==같이 보기==
==같이 보기==
*[[mysql CLI 사용]]
*[[Backup.sh]]
*[[Backup.sh]]
*[[Bash용 mysql query 함수]]
*[[Bash용 mysql query 함수]]

2013년 11월 4일 (월) 08:24 판

Bash에서 MySQL 접근
Bash에서 원격으로 MySQL 쿼리 수행

1 로컬

명령어
mysql -u아이디 -p패스워드 디비명 -e "쿼리문"
echo "쿼리문" | mysql -u아이디 -p패스워드 디비명
실행예시
[root@jmnote ~]# mysql -uroot -pP@ssw0rd mysql -e "SHOW TABLES"
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
... (생략)
| user                      |
+---------------------------+
[root@jmnote ~]# echo "SHOW TABLES" | mysql -uroot -pP@ssw0rd mysql
Tables_in_mysql
columns_priv
db
... (생략)
user

2 원격

명령어
mysql -h서버주소 -u아이디 -p패스워드 디비명 -e "쿼리문"
실행예시
[root@remote ~]# mysql -h111.222.33.44 -uroot -pP@ssw0rd mysql -e "SHOW TABLES"
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
... (생략)
| user                      |
+---------------------------+

3 여러 줄 입력

mysql -u아이디 -p패스워드 디비명 <<QUERY
쿼리문
QUERY
[root@jmnote ~]# mysql -uroot -pP@ssw0rd mysql <<QUERY
> SHOW
> TABLES;
> QUERY
Tables_in_mysql
columns_priv
db
.. (생략)
user

4 같이 보기

5 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}