前置知识

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

mysql -uroot -proot

在mysql中用户的信息会存放在 mysql数据库下的 user表中 可以像下面这样查看到所有用户信息

mysql> use mysql
Database changed
mysql> select * from user\G
*************************** 1. row ***************************Host: localhostUser: rootSelect_priv: YInsert_priv: YUpdate_priv: YDelete_priv: YCreate_priv: YDrop_priv: YReload_priv: YShutdown_priv: YProcess_priv: YFile_priv: YGrant_priv: YReferences_priv: YIndex_priv: YAlter_priv: YShow_db_priv: YSuper_priv: YCreate_tmp_table_priv: YLock_tables_priv: YExecute_priv: YRepl_slave_priv: YRepl_client_priv: YCreate_view_priv: YShow_view_priv: YCreate_routine_priv: YAlter_routine_priv: YCreate_user_priv: YEvent_priv: YTrigger_priv: Y
Create_tablespace_priv: Yssl_type:ssl_cipher:x509_issuer:x509_subject:max_questions: 0max_updates: 0max_connections: 0max_user_connections: 0plugin: mysql_native_passwordauthentication_string: *C85A9826269E1AD748DFC3CEC32D040735B27207password_expired: Npassword_last_changed: 2019-11-07 14:39:30password_lifetime: NULLaccount_locked: N
*************************** 2. row ***************************Host: localhostUser: mysql.sessionSelect_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.7Welcome 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

嗨!不来看一下如何骚气十足的登陆MySQL嘛?相关推荐

  1. 最骚气的APP更新文案盘点

    因为手机里 下了超多APP 每次打开AppStore都会很崩溃 这样的更新提示就问你怕不怕 要是一不小心按到「全部更新」 手机就彻底原!地!爆!炸! 所以我一般更新APP都会很谨慎 会看看更新了哪些东 ...

  2. 2020卫星参数表大全_王者荣耀比较秀的名字 2020年比较骚气比较浪的王者荣耀名字大全...

    游戏中该起什么样的名字,才能让其他玩家很快的记住,从而达到认识更多玩家,认识到更多的朋友,达到交友目的. 2020年比较骚气比较浪的王者荣耀男性玩家名字大全如下: 骚里骚气 闷里闷气 孤独患者 洁癖患 ...

  3. 【骚气的动效】外发光涟漪波纹动画、向外辐射动画效果,通常用于地图上面某一个扩散点效果

    第一种:两轮外发光叠加,第二轮外发光结束后再出现第一轮 /* 外发光动画.向外辐射动画效果 */$orangeColor: rgba(251, 193, 105, 0.6); %out-glow {& ...

  4. java代码里的JSON格式怎么写好看_谁会不爱让代码骚里骚气的VSCode扩展插件呢?...

    点击上方 "Python人工智能技术" 关注,星标或者置顶22点24分准时推送,第一时间送达 来自:公众号 读芯术 | 编辑:真经君 码农真经(ID:coder_experienc ...

  5. vscode怎么引用css_今天来安装一个骚气的 VS Code 主题

    最近一直在 VSCode 上刷 LeetCode 题目,写久了感觉界面有点沉闷,决定找一个酷炫的主题来醒目一下. 结果在 GitHub 上找到一个令人纸醉金迷的 VSCode 主题,GitHubDai ...

  6. js增加透明css样式,如何配置透明发光的骚气 vscode

    1 安装自定义 JS 和 CSS 插件 2 安装发光主题 3 添加样式配置文件 在 VSCode 安装目录(自己随便选择一个文件夹也可以),放入以下文件. 为了方便下载,文件整理到了 Github-J ...

  7. 三款很酷很骚气的底部导航

    早上好,骚年,我是小菜,我的公众号「菜鸟翻身」会推荐 GitHub 上好玩的项目,一分钟 get 一个优秀的开源项目,挖掘开源的价值,欢迎关注我. 底部导航栏是 APP 最常用的功能之一,想最初都是自 ...

  8. 计算机专业16字口号大全,口号大全霸气十足16字班级口号霸气押韵

    摘要: 口号大全霸气十足16字班级口号霸气押韵为你介绍班级口号如何设定最有吸引力,最能鼓舞同学们的士气?下文有途网小编给大家整理了一些简短霸气的押韵班级口号大全,供参考! 班级口号大全霸气押韵 1.天 ...

  9. 《代号反抗》定妆照曝光 黎一萱攻气十足尽显眼神杀

    由喵了个汪影业.拓影影业.帕拉丁文化传媒.凡人乐视文化传媒和点格影视联合出品,黄圣依.辰亦儒.黎一萱.马德钟等出演的硬科幻院线电影<星球战纪之代号反抗>近日曝光定妆照.黎一萱饰演的电脑高手 ...

最新文章

  1. 数字图像处理:第四章 点运算
  2. CentOS 搭建内部Yum源同步阿里Yum源
  3. Web学习之跨域问题及解决方案
  4. [dsu on tree]树上启发式合并总结(算法思想及模板附例题练习)
  5. ffmpeg提取音频播放器总结
  6. 索尼Xperia 5 II官方高清渲染图曝光:还是那个熟悉的小屏旗舰
  7. Sql server2005中如何格式化时间日期
  8. JavaScript学习(五十二)—继承、call方法和apply方法
  9. win7程序员御用主题包制作
  10. GitHub 下dist和src,dest目录的区别
  11. python的小程序分析_Python小程序,红楼梦关键词分析
  12. 成为IT精英,我奋斗了7年
  13. 华为 、锐捷、新华三、睿易网络设备怎么选
  14. win10计算机联接多个网络,如何设置win10电脑连接两个显示器?
  15. 【嵌入式开源库】MultiButton的使用,简单易用的事件驱动型按键驱动模块
  16. 学什么技术专业最有前途?
  17. Google Play渠道超过100M?尝试APK分包,面试资料分享
  18. 肖像画】别太认真,资金面绝非盘间博弈
  19. 简单了解一下什么是期权
  20. Kotlin插件 kotlin-android-extensions

热门文章

  1. Python迭代器itertools
  2. 颜语言(网络交往语言)
  3. ROS开发实践(十)——ROS多机通讯及网络配置讲解
  4. CSDN2022年度征文(十年磨一剑)
  5. python3 m venv venv_python3 -m venv filename_venv
  6. 苏格拉底和孔子的区别
  7. Android生成二维码根据类型进行并扫描解析
  8. Maven 打包异常
  9. JS - 数值处理(取整、四舍五入、随机数等)
  10. HCIP十二天---MPLS-VNP