1. how to connect to the database
mysql -- the CLI command for DBA--user, -u
--host, -h
--password, -p
--port
--protocol
--database DATABASE, -D
-A disable completion of table and column names
mysql < SQLfile.sql - execute the SQL batch
2. common commands:
here is the official help document about the mysql client command. these commands will take effect on the client only.- clear (\c) Clear the current input statement.
- connect (\r) Reconnect to the server. Optional arguments are db and host.
- delimiter (\d) Set statement delimiter.
- edit (\e) Edit command with $EDITOR.
- ego (\G) Send command to mysql server, display result vertically.
- exit (\q) Exit mysql. Same as quit.
- go (\g) Send command to mysql server.
- help (\h) Display this help.
- nopager (\n) Disable pager, print to stdout.
- notee (\t) Don't write into outfile.
- pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
- print (\p) Print current command.
- prompt (\R) Change your mysql prompt.
- quit (\q) Quit mysql.
- rehash (\#) Rebuild completion hash.
- source (\.) Execute an SQL script file. Takes a file name as an argument.
- status (\s) Get status information from the server.
- system (\!) Execute a system shell command.
- tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
- use (\u) Use another database. Takes database name as argument.
- charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
- warnings (\W) Show warnings after every statement.
- nowarning (\w) Don't show warnings after every statement.
I think the most important commands are:
use : switch between database;
MySQL>use mysql
Database changed
status: show briefly about the server performance
MySQL>MySQL>status
--------------
mysql Ver 14.14 Distrib 5.6.15, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database: mysql
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.15 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 14 min 31 sec
Threads: 1 Questions: 60 Slow queries: 0 Opens: 87 Flush tables: 1 Open tables: 80 Queries per second avg: 0.068
source: execute the SQL in batch
system: execute the shell
MySQL>system cat /var/tmp/test.sql
select user,host from user;
MySQL>source /var/tmp/test.sql
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | x002 |
+------+-----------+
4 rows in set (0.00 sec)
3. how to understand the prompt:
mysql> --- standard prompt-> --- waiting for statement delimiter
'> --- waiting for end of '
"> --- waiting for end of "
`> --- waiting for end of `
No comments:
Post a Comment