Linux (Centos7) 自定义全局命令(脚本)

导读:本篇文章讲解 Linux (Centos7) 自定义全局命令(脚本),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

比如mysql每次登录都要写入,比较麻烦

$ mysql -hlocalhost -P3306 -uroot -p123456
  • 自定义全局命令 mysqlrun

1、创建存放全局脚本的目录

$ mkdir /opt/shell/

2、将路径进入全局变量(配置)

$ echo "export PATH=/opt/shell:$PATH" >> /etc/profile

3、使配置生效

$ source /etc/profile

4、查看是否生效,/opt/shell存在

[root@hadoop100 ywl]$ echo $PATH 
/opt/shell:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

5、在/opt/shell目录创建自己的脚本

$ vim /opt/shell/mysqlrun
  • 文件内容
#!/bin/bash
mysql -hlocalhost -P3306 -uroot -p123456

6、脚本使其具有执行权限

$ chmod 777 /opt/shell/mysqlrun

7、成功,接下来,你就可以在任何目录运行mysqlrun命令使用mysql了

$ mysqlrun
[root@hadoop100 /]$ mysqlrun
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 10
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/92643.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!