#mysql:command not found

时间:2023-03-09 16:32:46
#mysql:command not found

一、问题描述

  1、在linux中已经安装好mysql,通过#ps -ef |grep mysql 能显示mysql已经启动,但去进入mysql命令页面出现如下问题:

   [root@root ~]# mysql u -p
-bash: mysql: command not found

  查找mysql是否已经启动

 [root@root ~]# ps -ef  | grep mysql
root 1172 1 0 18:28 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/service/mysql --pid-file=/service/mysql/root.pid
mysql 1285 1172 9 18:28 ? 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/service/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/service/mysql/root.err --pid-file=/service/mysql/root.pid
root 1440 1288 0 18:28 pts/1 00:00:00 grep mysql

  2、查找问题产生原因:

  原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
首先得知道mysql命令或mysqladmin命令的完整路径,比如mysql的路径是:/usr/local/mysql/bin/mysql,【此路经是mysql实际安装路径】我们则可以这样执行命令  

 [root@root bin]# ln -fs /usr/local/mysql/bin/mysql /usr/bin/

  3、连接mysql  

 [root@root bin]# mysql -u -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20 Source distribution 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> Ctrl-C -- exit!
Aborted