简体   繁体   中英

Cannot find mySQL -- get "command not found" error when trying to access mySQL from command line

I have previously installed, connected and uploaded to a WordPress mySQL database via SSH no problem. The people who run my server made a few configuration changes, and now I get a "bash: mysql: command not found" error when I try to log into mySQL via the command line on the same server to access the same database.

I am relatively new to all of this, so I am really not sure what to do. When I run "which mysql" I get a message that says there is no mysql in the /usr/bin directories. I can verify that mySQL is running between the fact that my site is still live and functioning and when I ran a command to test mysql (sorry I can't locate that right now) I got a message that said "mySQL works!" I find mysql files in several directories, but I'm not really sure what I am looking for and how I connect to it when I do find it. I am also not sure if this is user error, or if somehow someone moved or hid mySQL from me -- likely user error??

Any help is appreciated. Thank you!

MySQL Server is not MySQL Client.

Check if MySQL is running executing this command:

ps aux | grep mysql | grep -v grep

And install MySQL Client:

sudo apt-get install mysql-client # Or your distro command

If you have mysql server up and running on your server it's not mean you have a mysql client installed on this server.

try

ls -l /usr/bin/mysql*

do you see mysql binaries exactly present on system?

One more problem Linux has very strange behaviour when run binaries for another archetecture. for example if you run 32-bin executable on 64-bit system you will get error message "command or file not found", even if binaries actually present!

hope this help.

Although the MySQL is running, if you are not able to connect to the server using mysql command, then you might be missing to provide soft links

sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin

sudo ln -s /usr/local/mysql/bin/mysql /usr/bin

this should enable you to connect.

--Madhusudan Mudri

Now mysql-client has changed to default-mysql-client

hence command:

sudo apt-get install default-mysql-client

In order to get MySQL CLI working or to access mysql command from anywhere , there are a set of steps to be done to add it to the $PATH variable

firstly open a terminal, run following command

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

then to reload bash profile, run

. ~/.bash_profile 

now run,

mysql -u root -p 

enter the password which you gave during installation you should see the following result

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 MySQL Community Server - GPL

On your computer, run:

sudo apt-get update && sudo apt-get install mysql-server

Then you will get rid of

/home/.../some_bash_script.sh: line 123: mysql: command not found

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM