MySQL登录命令详解
MySQL登录命令详解
一、登录命令语法格式
mysql -u用户名 [-h主机名] -p密码 [-P端口号] [-D数据库名] [-eMySQL命令] [-S socket文件名]
参数说明:
(1)【-u用户名】或者【–user=用户名】:指定用户登录的用户名;
(2)【-p密码(p小写)】或者【–password=密码】:输入登录密码;
(3)【-h主机名或ip地址】或者【–host=主机名ip地址】:指定登录的主机名;
(4)【-P端口号(P大写)】或者【–port=端口号】:指定登录的MySQL的端口号;
(5)【-D数据库名】或者【–database=数据库名】:指定登录的数据库名称;
(6)【-S socket文件名】或者【–socket=socket文件名】:指定登录时使用的socket文件名。
(7)【-e MySQL命令】或者【–execute= MySQL命令】:在不登录MySQL的情况下执行MySQL命令。
二、登录本地数据库
如果需要登录本地数据库,只需要指定用户名(-u)和密码(-p)即可,不需要指定主机名(-h),命令如下:
[root@bogon ~]# mysql -uroot -pWgx123456.
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 4
Server version: 5.7.27-log 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>
三、登录远程数据库
如果希望登录远程数据库服务器,则必须在远程的MySQL服务器中创建登录账号并授予相应的访问权限。然后使用(-h)参数指定远程服务器的IP地址,使用(-P)参数指定远程服务器中MySQL的端口号。
1、先在IP地址为192.168.1.11的MySQL服务器中创建登录账户’zhang’@'192.168.1.%'并授予访问权限。命令如下:
mysql> select host,user from user;
+-------------+---------------+
| host | user |
+-------------+---------------+
| 192.168.1.% | zhang |
2、在IP地址为192.168.1.12的机器中执行如下登录命令:
[root@bogon ~]# mysql -uzhang -h192.168.1.11 -pWgx123456. -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 8
Server version: 5.7.27-log 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>
四、登录指定的数据库
使用show database查看MySQL服务器中的数据库如下:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| my_db |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
6 rows in set (0.00 sec)
然后退出MySQL,再使用如下的命令登录MySQL:
[root@bogon ~]# mysql -uroot -pWgx123456. -Dmy_db
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -AWelcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.27-log 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> select database();
+------------+
| database() |
+------------+
| my_db |
+------------+
1 row in set (0.00 sec)mysql>
可以看出,登录到MySQL之后进入了 my_db数据库。
五、使用(-e)参数在不登录MySQL的情况下执行MySQL命令
[root@bogon ~]# mysql -uroot -p -e "use my_db;select * from stu where class='物流1班';"
Enter password:
+------+-----------+--------+-----+------------+
| s_id | name | gender | age | class |
+------+-----------+--------+-----+------------+
| 1 | 张平 | 男 | 20 | 物流1班 |
| 2 | 王刚 | 男 | 21 | 物流1班 |
| 3 | 刘静 | 女 | 18 | 物流1班 |
| 4 | 张静静 | 女 | 21 | 物流1班 |
| 5 | 刘涛 | 男 | 19 | 物流1班 |
+------+-----------+--------+-----+------------+
MySQL登录命令详解相关推荐
- linux mysql 确认命令_LINUX启动/重启/停上MYSQL的命令(详解)
如何启动/停止/重启MySQL 一.启动方式 1.使用 service 启动:service mysqld start 2.使用 mysqld 脚本启动:/etc/inint.d/mysqld sta ...
- linux启动mysql命令_LINUX启动/重启/停上MYSQL的命令(详解)
如何启动/停止/重启MySQL 一.启动方式 1.使用 service 启动:service mysqld start 2.使用 mysqld 脚本启动:/etc/inint.d/mysqld sta ...
- Mysql常用命令详解
链接地址:http://www.cnblogs.com/linjiqin/archive/2013/03/01/2939384.html Mysql安装目录 数据库目录 /var/lib/mysql/ ...
- mysql grant命令详解_MySQL授权命令grant的使用方法详解
本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的简单格式可概括为: grant权限 on数据库对象 to用户 一.grant 普通数据用户,查询.插入.更新.删除 数 ...
- mysql show 命令详解_MYSQL show 命令详解
show tables或show tables from database_name或show database_name.tables; 解释:显示当前数据库中所有表的名称 show databas ...
- MySQL Explain命令详解--表的读取顺序,数据读取操作的类型等
表示索引中使用的字节数,可通过该列计算查询中使用的索引的长度(key_len显示的值为索引字段的最大可能长度,并非实际使用长度,即key_len是根据表定义计算而得,不是通过表内检索出的) 不损失精确 ...
- MySQL--mysqldump命令详解
MySQL–mysqldump命令详解 1.数据库信息 数据库地址:127.0.0.1 数据库用户名:root 数据库密码:1234 数据库名称:test1 数据库名称:test2 数据库名称:tes ...
- Navicat的mysql远程登录方法详解
Navicat的mysql远程登录方法详解 工具和前提 远程连接方法 疑惑问题 报错汇总 关闭并删除用户 引用 工具和前提 1.均在Navicat上面进行操作: 2.Navicat15的版本,本地数据 ...
- mysql 关键字 status_Mysql show status命令详解
Mysql show status命令详解 ## 介绍 SHOW STATUS提供服务器的状态信息. ## 命令用法 ```sql mysql> show status; mysql> s ...
- mysql命令行查看表的触发器_Mysql事项,视图,函数,触发器命令(详解)
事项开启和使用 //修改表的引擎 alter table a engine=myisam; //开启事务 begin; //关闭自动提交 set autocommit=0; //扣100 update ...
最新文章
- 大脑的学习方式如何,机器学习与生物学习的联系将提供「答案」
- python与数据思维基础目录_python入门知识思维路线图及环境配置
- oracle利用分隔符,组合查询想表达的任何话
- 吴恩达机器学习作业(1):线性回归
- 2020年中国智能客服行业研究报告
- 【Kafka】Kafka WARN Property ssl.keystore.location is not valid (kafka.utils.VerifiableProperties)
- Python——用assert语句来确保参数符合当前程序的要求
- 【简历模板】网站推荐
- TA-LIB】之MACD
- python卡方检验计算pvalue值_如何用python计算临界值(critical value)和p值(p value)(scipy)...
- C# word文档转换成PDF格式文档
- 使用data breakpoint 追踪地址寄存器被修改的问题
- 数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
- word生成freemarker模板 并下载
- python折线图绘制——记录
- 0~6岁儿童不同时期微量元素含量的结果分析
- 渗透杂记-2013-07-10
- 你管这破玩意叫“小程序”?
- cisco 内存利用率oid_交换机CPU、内存OID获取 | 聂扬帆博客
- mysql格式化日期如果日期为空_为什么在使用MySQL数据库格式化日期时,此查询会提供一个空集?...