mysql 5.7.33 命令詳解 (未集成)


開源數據庫。

另請參閱: dd     free     myisamchk

基本用法     詳細用法

mysql --version
			

基本語法

mysql [OPTIONS] [database]
			

mysql client 組可讀。

Options 選項


默認選項讀取自以下文件 (按給定次序):

/etc/my.cnf

/etc/mysql/my.cnf

~/.my.cnf

參數 EN 解釋 中文翻譯 備注
-?, --help Display this help and exit. 顯示此幫助並退齣。
-I, --help Synonym for -? -? 同義詞
--auto-rehash

Enable automatic rehashing.

One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time.

Disable with --disable-auto-rehash.

(Defaults to on; use --skip-auto-rehash to disable.)

啓用自動重新哈希。

不需要使用重新哈希完成錶和字段,但啓動和重新連接可能需要更長時間。

禁用采用 --disable-auto-rehash。

(默認為 on;使用 --skip-auto-rehash 去禁用。)

-A, --no-auto-rehash

No automatic rehashing.

One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect.

不自動重新哈希。

必須使用重新哈希完成錶和字段。 這樣可更快啓動 mysql 並在重新連接時禁用重新哈希。

--auto-vertical-output Automatically switch to vertical output mode if the result is wider than the terminal width. 自動切換到垂直輸齣模式,若結果寬於終端寬度。
-B, --batch

Don't use history file.

Disable interactive behavior.

(Enables --silent.)

不使用曆史記錄文件。

禁用交互行為。

(啓用 --silent)

--bind-address=name IP address to bind to. 綁定 IP 地址。
--binary-as-hex Print binary data as hex 將二進製數據打印為十六進製
--character-sets-dir=name Directory for character set files. 字符集文件的目錄。
-column-type-info Display column type information. 顯示列類型信息。
-c, --comments

Preserve comments.

Send comments to the server.

The default is --skip-comments (discard comments), enable with --comments.

保留。

把注釋發送給服務器。

默認為 --skip-comments (丟棄注釋),啓用采用 --comments。

-C, --compress Use compression in server/client protocol. 在服務器/客戶端協議中使用壓縮。
-#, --debug[=#] This is a non-debug version. Catch this and exit. 這是非調試版本。捕獲這並退齣。
--debug-check This is a non-debug version. Catch this and exit. 這是非調試版本。捕獲這並退齣。
-T, --debug-info This is a non-debug version. Catch this and exit. 這是非調試版本。捕獲這並退齣。
-D, --database=name Database to use. 要使用的數據庫。
--default-character-set=name Set the default character set. 設置默認字符集。
--delimiter=name Delimiter to be used. 要使用的定界符。
--enable-cleartext-plugin nable/disable the clear text authentication plugin. 啓用/禁用明文身份驗證插件。
-e, --execute=name Execute command and quit. (Disables --force and history file.) 執行命令並離開。(禁用 --force 的曆史記錄文件。)
-E, --vertical Print the output of a query (rows) vertically. 垂直打印查詢 (行) 輸齣。
-f, --force Continue even if we get an SQL error. 即使遇到 SQL 錯誤仍繼續。
--histignore=name A colon-separated list of patterns to keep statements from getting logged into syslog and mysql history. 冒號分隔的模式列錶以防止語句來自登陸 syslog 和 mysql 曆史記錄。
-G, --named-commands

Enable named commands.

Named commands mean this program's internal commands; see mysql> help.

When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter.

Disable with --disable-named-commands.

This option is disabled by default.

啓用命名命令。

命名命令錶示該程序的內部命令;見 mysql> 幫助。

當啓用時,可以在任何查詢行中使用命名命令,否則隻可在迴車之前的第一行中使用。

禁用采用 --disable-named-commands。

此選項默認情況下是禁用的。

-i, --ignore-spaces Ignore space after function names. 忽略函數名後的空格。
--init-command=name

SQL Command to execute when connecting to MySQL server.

Will automatically be re-executed when reconnecting.

要執行的 SQL 命令當連接到 MySQL 服務器時。

將自動重新執行當重新連接時。

--local-infile Enable/disable LOAD DATA LOCAL INFILE. 啓用/禁用 LOAD DATA LOCAL INFILE。
-b, --no-beep Turn off beep on error. 關閉齣錯時的嗶嗶聲。
-h, --host=name Connect to host. 連接到主機。
-H, --html Produce HTML output. 産生 HTML 輸齣。
-X, --xml Produce XML output. 産生 XML 輸齣。
--line-numbers

Write line numbers for errors.

(Defaults to on; use --skip-line-numbers to disable.)

寫入錯誤行號。

(默認為 on;使用 --skip-line-numbers 去禁用)

-L, --skip-line-numbers Don't write line number for errors. 不寫入錯誤行號。
-n, --unbuffered Flush buffer after each query. 每次查詢之後刷新緩衝。
--column-names

Write column names in results.

(Defaults to on; use --skip-column-names to disable.)

在結果中寫入列名。

(默認為 on;使用 --skip-column-names 去禁用)

-N, --skip-column-names Don't write column names in results. 不在結果中寫入列名。
--sigint-ignore Ignore SIGINT (CTRL-C). 忽略 SIGINT (CTRL-C)。
-o, --one-database Ignore statements except those that occur while the default database is the one named at the command line. 忽略語句,除默認數據庫是在命令行中一命名語句外。
--pager[=name]

Pager to use to display results.

If you don't supply an option, the default pager is taken from your ENV variable PAGER.

Valid pagers are less, more, cat [> filename], etc.

See interactive help (\h) also.

This option does not work in batch mode.

Disable with --disable-pager.

This option is disabled by default.

用於顯示結果的尋呼機。

若不提供選項,默認尋呼機將獲取自 ENV 變量 PAGER。

有效尋呼機包括:less、more、cat [> filename]、等。

另請參閱交互幫助 (\h)。

此選項在批處理模式下不起作用。

禁用采用 --disable-pager。

此選項默認情況下是禁用的。

-p, --password[=name]

Password to use when connecting to server.

If password is not given it's asked from the tty.

連接到服務器時要使用的口令。

若口令未給定,則從 tty 詢問。

-P, --port=# Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306). 用於連接的端口號,或默認為 0,按優先次序依次為 my.cnf、$MYSQL_TCP_PORT、/etc/services、內置默認 3306。
--prompt=name Set the mysql prompt to this value. 將 mysql 提示設為此值。
--protocol=name The protocol to use for connection (tcp, socket, pipe, memory). 用於連接的協議 (TCP、套接字、管道、內存)。
-q, --quick

Don't cache result, print it row by row.

This may slow down the server if the output is suspended.

Doesn't use history file.

不緩存結果,逐行打印。

這可能降低服務器速度,若輸齣被掛起。

不使用曆史記錄文件。

-r, --raw Write fields without conversion. Used with --batch. 不轉換寫入字段。與 --batch 一起使用。
--reconnect

Reconnect if the connection is lost.

Disable with --disable-reconnect.

This option is enabled by default.

(Defaults to on; use --skip-reconnect to disable.)

重新連接若連接丟失。

禁用采用 --disable-reconnect。

此選項默認情況下是啓用的。

(默認為 on;使用 --skip-reconnect 去禁用)

-s, --silent

Be more silent.

Print results with a tab as separator, each row on new line.

更沉默。

用製錶符作為分隔符打印結果,每行換行。

-S, --socket=name The socket file to use for connection. 用於連接的套接字文件。
-ssl-mode=name SSL connection mode. SSL 連接模式。
--ssl

Deprecated. Use --ssl-mode instead.

(Defaults to on; use --skip-ssl to disable.)

棄用。使用 --ssl-mode 代替。

(默認為 on;使用 --skip-ssl 去禁用)

--ssl-verify-server-cert Deprecated. Use --ssl-mode=VERIFY_IDENTITY instead. 棄用。使用 --ssl-mode=VERIFY_IDENTITY 代替。
--ssl-ca=name CA file in PEM format. 采用 PEM 格式的 CA 文件。
--ssl-capath=name CA directory. CA 目錄。
--ssl-cert=name X509 cert in PEM format. 采用 PEM 格式的 X509 證書。
--ssl-cipher=name SSL cipher to use. 要使用的 SSL 暗號。
--ssl-key=name X509 key in PEM format. 采用 PEM 格式的 X509 密鑰。
--ssl-crl=name Certificate revocation list. 證書吊銷列錶。
--ssl-crlpath=name Certificate revocation list path. 證書吊銷列錶路徑。
-tls-version=name TLS version to use, permitted values are: TLSv1, TLSv1.1, TLSv1.2 要使用的 TLS 版本,容許值:TLSv1、TLSv1.1、TLSv1.2
--server-public-key-path=name File path to the server public RSA key in PEM format. 采用 PEM 格式的服務器公共 RSA 密鑰的文件路徑。
--get-server-public-key Get server public key 獲取服務器公共密鑰
-t, --table Output in table format. 按錶格格式輸齣。
--tee=name

Append everything into outfile.

See interactive help (\h) also.

Does not work in batch mode.

Disable with --disable-tee.

This option is disabled by default.

將所有事情追加到輸齣文件。

另請參閱交互幫助 (\h)。

在批處理模式下不起作用。

禁用采用 --disable-tee。

此選項默認情況下是禁用的。

-u, --user=name User for login if not current user. 登錄用戶,若不是當前用戶。
-U, --safe-updates Only allow UPDATE and DELETE that uses keys. 隻允許 UPDATE 和 DELETE 使用鍵。
-U, --i-am-a-dummy Synonym for option --safe-updates, -U. 選項 --safe-updates、-U 的同義詞。
-v, --verbose Write more. (-v -v -v gives the table output format). 寫入更多 (-v -v -v 給齣錶的輸齣格式)。
-V, --version Output version information and exit. 輸齣版本信息並退齣。
-w, --wait Wait and retry if connection is down. 等待並重試若連接斷開。
--connect-timeout=# Number of seconds before connection timeout. 在連接超時之前的秒數。
--max-allowed-packet=# The maximum packet length to send to or receive from server. 發送到或接收自服務器的最大數據包長度。
--net-buffer-length=# The buffer size for TCP/IP and socket communication. TCP/IP 和套接字通信的緩衝大小。
--select-limit=# Automatic limit for SELECT when using --safe-updates. 對 SELECT 的自動限製當使用 --safe-updates 時。
--max-join-size=# Automatic limit for rows in a join when using --safe-updates. 對聯接行的自動限製當使用 --safe-updates 時。
--secure-auth Refuse client connecting to server if it uses old (pre-4.1.1) protocol. Deprecated. Always TRUE 拒絕客戶端連接到服務器,若客戶端使用舊的 (4.1.1 之前版本) 協議。棄用。始終 TRUE
--server-arg=name Send embedded server this as a parameter. 發送嵌入式服務器作為參數。
--show-warnings Show warnings after every statement. 在每個語句之後展示警告。
-j, --syslog

Log filtered interactive commands to syslog.

Filtering of commands depends on the patterns supplied via histignore option besides the default patterns.

將過濾後的交互式命令日誌到 syslog。

命令的過濾取決於憑藉 histignore 選項提供的模式,除默認模式外。

--plugin-dir=name Directory for client-side plugins. 客戶端側插件的目錄。
--default-auth=name Default authentication client-side plugin to use. 要使用的默認身份驗證客戶端側插件。
--binary-mode

By default, ASCII '\0' is disallowed and '\r\n' is translated to '\n'.

This switch turns off both features, and also turns off parsing of all clientcommands except \C and DELIMITER,

in non-interactive mode (for input piped to mysql or loaded using the 'source' command).

This is necessary when processing output from mysqlbinlog that may contain blobs.

默認情況下,ASCII \0 是不允許的,且 \r\n 會被翻譯成 \n。

此開關關閉這兩特徵,且還能關閉所有客戶端命令 (除 \C 和 DELIMITER 外)的剖析,

在非交互模式下 (用於通過管道輸入到 mysql 或使用 source 命令加載輸入)。

這是必要的,當處理來自可能包含 blobs 的 mysqlbinlog 的輸齣時。

--connect-expired-password Notify the server that this client is prepared to handle expired password sandbox mode. 通知:此客戶端服務器已準備處理過期口令沙箱模式。

可給定作為第一自變量的選項

參數 EN 解釋 中文翻譯 備注
--print-defaults Print the program argument list and exit. 打印程序自變量列錶並退齣。
--no-defaults Don't read default options from any option file, except for login file. 不要從任何選項文件中讀取默認選項,除登錄文件外。
--defaults-file=# Only read default options from the given file #. 僅從給定文件 # 中讀取默認選項。
--defaults-extra-file=# Read this file after the global files are read. 讀取此文件,在讀取全局文件之後。
--defaults-group-suffix=# Also read groups with concat(group, suffix) 還讀取組采用 concat(group, suffix)
--login-path=# Read this path from the login file. 從登錄文件讀取此路徑。

Variables 變量

變量 解釋 備注
auto-rehash TRUE
auto-vertical-output FALSE
bind-address (No default value) (無默認值)
binary-as-hex FALSE
character-sets-dir (No default value) (無默認值)
column-type-info FALSE
comments FALSE
compress FALSE
database (No default value) (無默認值)
default-character-set auto 自動
delimiter ;
enable-cleartext-plugin FALSE
vertical FALSE
force FALSE
histignore (No default value) (無默認值)
named-commands FALSE
ignore-spaces FALSE
init-command (No default value) (無默認值)
local-infile FALSE
no-beep FALSE
host (No default value) (無默認值)
html FALSE
xml FALSE
line-numbers TRUE
unbuffered FALSE
column-names TRUE
sigint-ignore FALSE
port 0
prompt mysql>
quick FALSE
raw FALSE
reconnect TRUE
socket (No default value) (無默認值)
ssl TRUE
ssl-verify-server-cert FALSE
ssl-ca (No default value) (無默認值)
ssl-capath (No default value) (無默認值)
ssl-cert (No default value) (無默認值)
ssl-cipher (No default value) (無默認值)
ssl-key (No default value) (無默認值)
ssl-crl (No default value) (無默認值)
ssl-crlpath (No default value) (無默認值)
tls-version (No default value) (無默認值)
server-public-key-path (No default value) (無默認值)
get-server-public-key FALSE
table FALSE
user (No default value) (無默認值)
safe-updates FALSE
i-am-a-dummy FALSE
connect-timeout 0
max-allowed-packet 16777216
net-buffer-length 16384
select-limit 1000
max-join-size 1000000
secure-auth TRUE
show-warnings FALSE
plugin-dir (No default value) (無默認值)
default-auth (No default value) (無默認值)
binary-mode FALSE
connect-expired-password FALSE

基本用法

功能 命令 文字解釋 示例 示例解釋
幫助 mysql -? 展示幫助信息
mysql -I
mysql --help

詳細用法

apt-get update --> apt-get dist-upgrade
 
apt-get install mysql-server --> root 用戶口令 6 --> dpkg -l mysql-server
 
mysql -v -u root -p (檢查 MySQL 版本,若提示錯誤請清潔移除再安裝) --> 口令 6 --> exit --> service mysql status (檢查 MySQL 狀態,若提示錯誤請清潔移除再安裝)
 
apt-get install mysql-client --> dpkg -l mysql-client
			

管理數據庫

mysql -v -u root -p (檢查 MySQL 版本,若提示錯誤請清潔移除再安裝) --> 口令 6 --> SHOW DATABASES;
 
創建數據庫
CREATE DATABASE 數據庫名;
 
移除數據庫
drop database 數據庫名;
			

啓動服務

service mysql restart
 
/etc/init.d/mysql stop 或 service mysql stop
 
/etc/init.d/mysql start 或 service mysql start
			

目錄結構

日誌文件
/var/log/mysql/error.log
 
配置文件
/etc/mysql/my.cnf
/etc/mysql/my.cnf.fallback
 
/etc/mysql/conf.d
/etc/mysql/mysql.conf.d
			

清潔移除 (包括現有數據庫)

apt-get update --> apt-get dist-upgrade
 
cd / --> apt-get purge mysql* --> apt-get autoremove --> find / -name mysql* --> find / -name mysql* | xargs rm -rf
			

解決錯誤

問題
[ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12 #可用內存不足
解決辦法
free -m #查看內存使用情況
每次重啓後手動增加 swap 內存空間
 
vi /etc/mysql/my.cnf.fallback #編輯配置文件
innodb_buffer_pool_size = 8MB #結尾添加,設置內存範圍 8-128MB (小於可用內存)
			

 

版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。