当前位置:网站首页>嗨!不来看一下如何骚气十足的登陆MySQL嘛?
嗨!不来看一下如何骚气十足的登陆MySQL嘛?
2022-08-02 20:52:00 【马小屑】
前置知识
我们想登陆到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'
[email protected]'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
[[email protected] ~]#
在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
边栏推荐
- golang刷leetcode: 卖木头块
- PLC工作原理动画
- Li Mu hands-on deep learning V2-BERT pre-training and code implementation
- Details in C# you don't know
- YARN资源调度系统介绍
- apache calcite中关于model文件配置
- 信息学奥赛一本通(1260:【例9.4】拦截导弹(Noip1999))
- golang 刷leetcode:将字符串翻转到单调递增
- 无线振弦采集仪远程修改参数的方式
- 包管理工具npm- node package management相关知识 、检查包更新、NPM包上传、更换镜像、npm ERR! registry error parsing json
猜你喜欢

.NET性能优化-你应该为集合类型设置初始大小

用户之声 | 大学生的“课外学堂”
![[C题目]力扣142. 环形链表 II](/img/b0/1e92f0f178089fc12cf88072d28912.png)
[C题目]力扣142. 环形链表 II

封装和包、访问修饰权限

.NET如何快速比较两个byte数组是否相等

用了TCP协议,就一定不会丢包吗?

汉源高科千兆4光4电工业级网管型智能环网冗余以太网交换机防浪涌防雷导轨式安装

Tencent YunMeng every jie: I experienced by cloud native authors efficiency best practices case
VisualStudio 制作Dynamic Link Library动态链接库文件

《分布式微服务电商》专题(一)-项目简介
随机推荐
千人优学 | GBase 8s数据库2022年6月大学生专场实训圆满结束
JMeter的基本使用
php 单引号 双引号 -> => return echo
A brief discussion on the transformation of .NET legacy applications
Xcode13.1 run engineering error fatal error: 'IFlyMSC/IFly h' file not found
无线振弦采集仪远程修改参数的方式
「每周译Go」这次我们来点不一样的!--《How to Code in Go》系列上线
【实战 已完结】WPF开发自动化生产管理平台
并发与并行
Swin Transformer 论文精读,并解析其模型结构
PyRosetta 安装方法之Conda安装
golang 刷leetcode:将字符串翻转到单调递增
回文自动机+CodeTON Round 2 C,D
sre成长之路
golang刷leetcode:道路的最大总重要性
【3D视觉】深度摄像头与3D重建
供电系统电气图
The five classification of software testing
用户之声 | GBASE南大通用实训有感
ACE JET NPOI