1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| 1>连接数据库 -u 用户 -p 密码 -h IP -P 端口 -S socket文件 -e 免交互执行命令 < 导入SQL脚本
[root@db01 ~]# mysql -uroot -p -h 10.0.0.51 -P3306 Enter password: mysql> select @@socket; +-----------------+ | @@socket | +-----------------+ | /tmp/mysql.sock | [root@db01 ~]# mysql -uroot -p -S /tmp/mysql.sock Enter password: [root@db01 ~]# mysql -uroot -p -e "select user,host from mysql.user;" Enter password: +---------------+-----------+ | user | host | +---------------+-----------+ | abc | 10.0.0.% | | app | 10.0.0.% | | root | 10.0.0.% | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ [root@db01 ~]# [root@db01 ~]# mysql -uroot -p <world.sql Enter password: [root@db01 ~]#
2>内置命令: help #打印mysql帮助文档 \c #结束上个命令运行 \q #退出mysql \G #竖屏显示数据 source #恢复数据备份文件 #其他内置命令可以使用help查看 mysql> help
For information about MySQL products and services, visit: http://www.mysql.com/ For developer information, including the MySQL Reference Manual, visit: http://dev.mysql.com/ To buy MySQL Enterprise support, training, or other products, visit: https://shop.mysql.com/
List of all MySQL commands: Note that all text commands must be first on line and end with ';' ? (\?) Synonym for `help'. 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 cha rsets.warnings (\W) Show warnings after every statement. nowarning (\w) Don't show warnings after every statement. resetconnection(\x) Clean session context.
For server side help, type 'help contents'
mysql>
|