无法用指定MySQL客户端登陆服务器的案例分析(6)

发现/usr/bin是在/usr/local/mysql这个路径之前的,这里做一个假设,系统先读到/usr/bin之后就直接运行了5.0.96的mysql客户端,而不管之后的路径了,所以即便推出session重新连接,始终都是先进入/usr/bin读取mysql。来验证一下,把这2个位置对调一下

 

[root@bak ~]# export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/local/mysql/bin:/usr/bin:/root/bin

[root@bak ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.0.96-community-log MySQL Community Edition (GPL)

 

Copyright (c) 2000, 2014, 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> \s

--------------

mysql  Ver 14.14 Distrib 5.5.39, for linux2.6 (i686) using readline 5.1    --又以5.5.39的客户端连接到5.0.96的服务器了

 

Connection id:          8

Current database:

Current user:           root@localhost

SSL:                    Not in use

Current pager:          stdout

Using outfile:          ''

Using delimiter:        ;

Server version:         5.0.96-community-log MySQL Community Edition (GPL)

Protocol version:       10

Connection:             Localhost via UNIX socket

Server characterset:    latin1

Db     characterset:    latin1

Client characterset:    utf8

Conn.  characterset:    utf8

UNIX socket:            /var/lib/mysql/mysql.sock

Uptime:                 21 min 15 sec

 

Threads: 1  Questions: 32  Slow queries: 0  Opens: 12  Flush tables: 1  Open tables: 6  Queries per second avg: 0.025

--------------

 

mysql> 

 

不过这样做并没有固化到环境变量中,退出session以后再连上,PATH又变成之前的值了,就算source .bash_profile也是如此,来看一下root用户的.bash_profile文件

 

[root@bak ~]# cat .bash_profile

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

 

# User specific environment and startup programs

 

PATH=$PATH:$HOME/bin

 

export PATH

unset USERNAME

[root@bak ~]# 

 

这里面没有显示指定PATH的具体值是哪些,只是用$调用了一下PATH变量,既然这样,我们就把期望的值写进去,然后就可以做到固化PATH路径的绝对值了

 

[root@bak ~]# vi .bash_profile

把$PATH改为

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/local/mysql/bin:/usr/bin:/root/bin

 

[root@bak ~]# . .bash_profile    --使环境变量在当前session生效

 

这样,即使退出session也不会丢失给PATH设置的值了,当我们需要哪个版本的客户端时,就手动调整一下PATH的路径,让目标路径放在前面供系统查找即可

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/209eb7c89bdb1b28ad704950da12e930.html