阅读原文

系列文章公众号首发,点击阅读原文

前置知识

我们想登陆到mysql中前提是肯定需要一个用户名和密码:比如

mysql -uroot -proot

在mysql中用户的信息会存放在 mysql数据库下的 user表中

可以像下面这样查看到所有用户信息

mysql> use mysql
Database changed
mysql> select * from user\G
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *C85A9826269E1AD748DFC3CEC32D040735B27207
password_expired: N
password_last_changed: 2019-11-07 14:39:30
password_lifetime: NULL
account_locked: N
*************************** 2. row ***************************
Host: localhost
User: mysql.session
Select_priv: N

其中有一列叫做HOST,HOST的不同值决定了用户拥有不同的登陆方式:比如:

标识符 含义
% 任意ip均等登陆
localhost 只允许本地登陆
127.0.0.1 只允许本地登陆
sv1 主机名为sv1的机器可登录,主机名可以在 /etc/hostname中查看
::1 本机可登录

所以在登陆前,请确定你的使用的登陆用户的HOST列中有相应的配置

骚气的登陆

在mac上登陆华为云的服务器

MacBook-Pro% ssh 'root'@'139.9.92.123'
root@139.9.92.123's password:
Last failed login: Fri May 29 11:03:42 CST 2020 from 202.85.208.14 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Thu May 28 16:36:32 2020 from 202.85.208.7 Welcome to Huawei Cloud Service -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
[root@139 ~]#

在mac上远程登陆服务器上的mysql

MacBook-Pro% ./mysql -h139.9.92.123 -uroot -reqw123.. -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 2174
Server version: 5.7.29 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |

mac登陆本地的mysql

如果你有配置环境变量,或者你的mysql的可执行文件在/etc/bin中,那你可以在任何目录中使用mysql命令

你可以直接像下面这样登陆:

MacBook-Pro% mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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命令,需要你进入到mysql安装目录下的bin文件下,找到mysql命令,然后执行登陆的动作

MacBook-Pro% /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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

MacBook-Pro% mysql -h127.0.0.1 -uroot -proot -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 4
Server version: 5.7.30 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| assignment |
| cal |

本地登陆

我们可以借助mysql.sock实现本地登陆。

那这个mysql.sock是什么?

看起来我们需要了解一下mysql.sock的作用,因为通过它我们可以实现mysql的本地登陆。

mysql.sock应该是mysql的主机和客户机在同一host(物理服务器)上的时候,使用unix domain socket做为通讯协议的载体,它比tcp快。

通过命令可以查看到mysql.sock的位置。

MacBook-Pro% netstat -ln | grep mysql
64e3f4c55eb824d7 stream 0 0 64e3f4c5614859a7 0 0 0 /tmp/mysql.sock

记下这个 mysql.sock的地址。接下来我们会创建一个配置文件,你找个看着比较顺眼的目录放置这个配置文件。

比如就像下面这样:

MacBook-Pro% sudo mkdir etc
MacBook-Pro% ls -l
total 552
-rw-r--r-- 1 root wheel 275235 Mar 24 01:35 LICENSE
-rw-r--r-- 1 root wheel 587 Mar 24 01:35 README
drwxr-xr-x 40 root wheel 1280 Mar 24 02:45 bin
drwxr-x--- 27 _mysql _mysql 864 May 28 20:44 data
drwxr-xr-x 5 root wheel 160 Mar 24 02:44 docs
drwxr-xr-x 2 root wheel 64 May 29 11:39 etc
drwxr-xr-x 53 root wheel 1696 Mar 24 02:44 include
drwxr-x--- 3 _mysql _mysql 96 May 28 20:44 keyring
drwxr-xr-x 11 root wheel 352 May 13 09:16 lib
drwxr-xr-x 4 root wheel 128 Mar 24 02:44 man
drwxr-xr-x 39 root wheel 1248 Mar 24 02:44 share
drwxr-xr-x 6 root wheel 192 May 28 19:20 support-files
MacBook-Pro% cd etc
MacBook-Pro% sudo touch user.root.cnf
MacBook-Pro% sudo vim user.root.cnf

然后在 user.root.cnf 中添加如下的配置:

[client]
user=root
password=root
socket=/tmp/mysql.sock

好了,现在可以这样实现本地登陆

MacBook-Pro% ../bin/mysql --defaults-extra-file=./user.root.cnf
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.30 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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时直接使用命令: mysql.local 就骚气十足的本地登陆mysql

他是怎么做到的呢?其实很简单、借助alias+mysql.sock实现:

为我们的登陆mysql的命令添加别名,像下面这样:

MacBook-Pro% alias mysql.local='/usr/local/mysql/bin/mysql --defaults-extra-file=/usr/local/mysql/etc/user.root.cnf'
MacBook-Pro% mysql.local
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.30 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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

推荐阅读

  1. MySQL的修仙之路,图文谈谈如何学MySQL、如何进阶!(已发布)
  2. 面前突击!33道数据库高频面试题,你值得拥有!(已发布)
  3. 大家常说的基数是什么?(已发布)
  4. 讲讲什么是慢查!如何监控?如何排查?(已发布)
  5. 对NotNull字段插入Null值有啥现象?(已发布)
  6. 能谈谈 date、datetime、time、timestamp、year的区别吗?(已发布)
  7. 了解数据库的查询缓存和BufferPool吗?谈谈看!(已发布)
  8. 你知道数据库缓冲池中的LRU-List吗?(已发布)
  9. 谈谈数据库缓冲池中的Free-List?(已发布)
  10. 谈谈数据库缓冲池中的Flush-List?(已发布)
  11. 了解脏页刷回磁盘的时机吗?(已发布)
  12. 用十一张图讲清楚,当你CRUD时BufferPool中发生了什么!以及BufferPool的优化!(已发布)
  13. 听说过表空间没?什么是表空间?什么是数据表?(已发布)
  14. 谈谈MySQL的:数据区、数据段、数据页、数据页究竟长什么样?了解数据页分裂吗?谈谈看!(已发布)
  15. 谈谈MySQL的行记录是什么?长啥样?(已发布)
  16. 了解MySQL的行溢出机制吗?(已发布)
  17. 说说fsync这个系统调用吧! (已发布)
  18. 简述undo log、truncate、以及undo log如何帮你回滚事物! (已发布)
  19. 我劝!这位年轻人不讲MVCC,耗子尾汁! (已发布)
  20. MySQL的崩溃恢复到底是怎么回事? (已发布)
  21. MySQL的binlog有啥用?谁写的?在哪里?怎么配置 (已发布)
  22. MySQL的bin log的写入机制 (已发布)
  23. 删库后!除了跑路还能干什么?(已发布)
  24. 自导自演的面试现场,趣学数据库的10种文件(已发布)
  25. 大型面试现场:一条update sql执行都经历什么?(已发布)
  26. 大型翻车现场:如何实现记录存在的话就更新,如果记录不存在的话就插入。(已发布)
  27. 视频+图文串讲:MySQL 行锁、间隙锁、Next-Key-Lock、以及实现记录存在的话就更新,如果记录不存在的话就插入如何保证并发安全(已发布)
  28. 自导自演的面试现场:说说char 和 varchar的区别你了解多少?。(已发布)
  29. 自导自演的面试现场之--你竟然不了解MySQL的组提交?。(已发布)
  30. 全网最清楚的:MySQL的insert buffer和change buffer 串讲(已发布)
  31. Double Write并不难理解
  32. 简述MySQL的三大范式

白日梦的MySQL专题(第33篇):各种登陆MySQL的骚操作的更多相关文章

  1. asp.net signalR 专题—— 第四篇 模拟RPC模式的Hub操作

    在之前的文章中,我们使用的都是持久连接,但是使用持久连接的话,这种模拟socket的形式使用起来还是很不方便的,比如只有一个唯一的 OnReceived方法来处理业务逻辑,如下图: protected ...

  2. 【linux】Centos下登陆mysql报错#1045 - Access denied for user 'root'@'localhost' (using password: NO)

    创建mysql  远程链接 grant all privileges on *.* to 'test'@"%" identified by "test666 with g ...

  3. 白日梦的MySQL专题(第38篇文章)8分钟回顾MySQL的索引

    目录 公众号首发-推荐阅读原文-格式更好看 一.导读 二.聚簇索引 三.二级索引 四.联合索引 4.1.什么是联合索引 4.2.左前缀原则 4.3.联合索引的分组&排序 五.覆盖索引 六.倒排 ...

  4. 「mysql优化专题」这大概是一篇最好的mysql优化入门文章(1)

    优化,一直是面试最常问的一个问题.因为从优化的角度,优化的思路,完全可以看出一个人的技术积累.那么,关于系统优化,假设这么个场景,用户反映系统太卡(其实就是高并发),那么我们怎么优化? 如果请求过多, ...

  5. mysql 开发进阶篇系列 39 mysql日志之二进制日志(binlog)

    一.概述 二进制日志(binlog)记录了所有的DDL(数据定义语言)语句和DML(数据操纵语言)语句,但是不包括数据查询语句, 语句以"事件"的形式保存,它描述了数据的更改过程, ...

  6. 【大型网站技术实践】初级篇:搭建MySQL主从复制经典架构

    一.业务发展驱动数据发展 随着网站业务的不断发展,用户量的不断增加,数据量成倍地增长,数据库的访问量也呈线性地增长.特别是在用户访问高峰期间,并发访问量突然增大,数据库的负载压力也会增大,如果架构方案 ...

  7. 无线安全专题_攻击篇--MAC泛洪攻击

    上一篇讲解了无线安全专题_攻击篇--干扰通信,没在首页待多长时间就被拿下了,看来之后不能只是讲解攻击实战,还要进行技术原理和防御方法的讲解.本篇讲解的是局域网内的MAC泛洪攻击,这种攻击方式主要目的是 ...

  8. (转) Eclipse连接MySQL数据库(傻瓜篇)

    Eclipse连接MySQL数据库(傻瓜篇) 原帖地址: http://www.cnblogs.com/fnng/archive/2011/07/18/2110023.html Posted on 2 ...

  9. CentOS 6.8下安装MySQL 5.6.33

    此处操作,包含MySQL的客户端及服务端. MySQL下载地址: http://dev.mysql.com/downloads/mysql/5.6.html MySQL--.linux_glibc2. ...

随机推荐

  1. Spark中普通集合与RDD算子的sortBy()有什么区别

    分别观察一下集合与算子的sortBy()的参数列表 普通集合的sortBy() RDD算子的sortBy() 结论:普通集合的sortBy就没有false参数,也就是说只能默认的升序排. 如果需要对普 ...

  2. redis的主从复制(哨兵模式)

    p.p1 { margin: 0; font: 10px ".SF NS Text" } Master以写为主,Slave以读为主 读写分离 容灾恢复 一.一主多从 配置文件修改: ...

  3. 如何自己设计一个类似dubbo的rpc框架?

    (1)上来你的服务就得去注册中心注册吧,你是不是得有个注册中心,保留各个服务的信息,可以用zookeeper来做,对吧 (2)然后你的消费者需要去注册中心拿对应的服务信息吧,对吧,而且每个服务可能会存 ...

  4. 如何识别自己基因组数据是哪个全基因组参考版本(Genome Reference Versions/ Genome Build)

    首先在这里先感谢我们[Bio生信学习交流群]的群友和创建此群的群主[陈博士后]. 今天解决的问题是怎么查看自己的基因组数据是哪个Genome Reference Versions. 步骤: 第一步,打 ...

  5. 爬虫简介、requests 基础用法、urlretrieve()

    1. 爬虫简介 2. requests 基础用法 3. urlretrieve() 1. 爬虫简介 爬虫的定义 网络爬虫(又被称为网页蜘蛛.网络机器人),是一种按照一定的规则,自动地抓取万维网信息的程 ...

  6. 机器人走方格-51nod解题

    M * N的方格,一个机器人从左上走到右下,只能向右或向下走. 有多少种不同的走法? 注意:给定 M, N 是一个正整数. 示例 输入: 1行, 2个数M,N,中间用空格隔开.(2 <= m,n ...

  7. CS与MSF之间的会话传递

    0x01 MSF会话传递到CS 1. CS上的操作 点击Cobalt Strike然后选择监听器,创建一个HTTPS Beacon的监听器即可 创建成功后如下 2. MSF上的操作 前提是已经获取到了 ...

  8. 『动善时』JMeter基础 — 3、JMeter插件管理

    JMeter是一个Java开发的开源软件,开源的软件有一个好处,就是会有很多第三方开发出来的插件,使得JMeter在处理某一些功能的时候更加的方便.并且这些插件拿过来就可以使用,完全免费的. 我们安装 ...

  9. BLDC有感FOC算法理论及其STM32软硬件实现

    位置传感器:旋转编码器          MCU:STM32F405RGT6          功率MOS驱动芯片:DRV8301 全文均假设在无弱磁控制的情况下 FOC算法理论 首先,我们要知道FO ...

  10. 修正js跳转

    var urls = new Array();urls["pc"] = "./hp"; //pcurls["sj"] = "./h ...