MySQL的连接管理及常用参数

1.MySQL数据库连接

  • 1.1MySQL:是一个典型的c/s结构的软件应用,用服务端有客户端,MySQL需要专门的客户端程序,来连接数据库进行管理和操作的。

2.连接方式

  • 2.1socket (本地登录使用)
[root@db01 ~]# mysql -uroot -p123  -S  /tmp/mysql.sock           #socket本地登录方式
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

注意:socket登录的前提,socket文件位置指定准确,必须要具备XXX@'localhost'相关的用户

  • 2.2TCP/IP登录
[root@db01 ~]# mysql -uzfs -p123456  -h10.0.0.91 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
  • 2.3通过软件工具远程登录
  • 2.3.1SQLyog远程连接


    SQLyog远程连接
  • 2.3.2Navicat for MySQL远程连接连接


    Navicat远程连接
  • 2.4MySQL常用参数介绍
参数 介绍
-u 用户名
-p 密码
-S socket文件目录
-h IP地址
-P 端口号(默认3306)
-e 免交互执行MySQL里的命令,不用登录进去
[root@db01 ~]# mysql -uroot -p123 -e "show databases;"
< 将脚本导入到数据库中
[root@db01 ~]# mysql -uroot -p123<world.sql
  • 2.5MySQL客户端内置功能
参数 介绍
help 打印帮助
/G 将行转成列显示
Ctrl+C 返回新的命令行(终止命令)
Ctrl+D,exit,quit 退出登录
source 导入脚本 (source /root/word.sql)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。