How do I install command line MySQL client on mac? - mysql

I want to install the MySQL client for the command line, not a GUI. I have searched over the web but only found instructions on installing the MySQL server.

install MySQLWorkbench, then
export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS

This strictly installs a command line client, without the other overhead:
Install Homebrew (if you don't have it):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then, install mysql-client:
brew install mysql-client
Then, add the mysql-client binary directory to your PATH:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
Finally, reload your bash profile:
source ~/.bash_profile
Then you should be able to run mysql in a terminal, if not try opening a new terminal

If you have already installed MySQL from the disk image (dmg) from http://dev.mysql.com/downloads/), open a terminal, run:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
then, reload .bash_profile by running following command:
. ~/.bash_profile
You can now use mysql to connect to any mysql server:
mysql -h xxx.xxx.xxx.xxx -u username -p
Credit & Reference: http://www.gigoblog.com/2011/03/13/add-mysql-to-terminal-shell-in-mac-os-x/

Best option is:
brew install mysql

Mysql has a client-only set of utilities:
Mysql client shell
https://dev.mysql.com/downloads/shell/
Other command line utilities
https://dev.mysql.com/downloads/utilities/
Mac OSX version available.

There is now a mysql-client formula.
brew install mysql-client

For installing mysql-shell with homebrew, run
brew cask install mysql-shell
you can then launch the mysql shell with
mysqlsh
if you want to enter SQL mode directly, run
mysqlsh --sql

Open the "MySQL Workbench" DMG file and
# Adjust the path to the version of MySQL Workbench you downloaded
cp "/Volumes/MySQL Workbench 6.3.9.CE/MySQLWorkbench.app/Contents/MacOS/mysql" /usr/local/bin
# Make sure it's executable
chmod +x /usr/local/bin/mysql
Eject the DMG disk

Installation command from brew:
$ brew cask install mysql-shell
Look at what you can do:
$ mysqlsh --help
Run query from mysqlsh client installed:
$ mysqlsh --host=192.x.x.x --port=3306 --user=user --password=xxxxx
MySQL Shell 8.0.18
Copyright (c) 2016, 2019, 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 '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a session to 'user#192.x.x.x:3306'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 16
Server version: 8.0.18 MySQL Community Server - GPL
No default schema selected;
type \use <schema> to set one.
MySQL 192.x.x.x:3306 ssl JS >
MySQL 192.x.x.x:3306 ssl JS > `\use rafdb`
Default schema set to `rafdb`.

If you installed from the DMG on a mac, it created a mysql client but did not put it in your user path.
Add this to your .bash_profile:
export PATH="/usr/local/mysql/bin:$PATH
This will let you run mysql from anywhere as you.

As stated by the earlier answer you can get both mysql server and client libs by running
brew install mysql.
There is also client only installation. To install only client libraries run
brew install mysql-connector-c
In order to run these commands, you need homebrew package manager in your mac. You can install it by running
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Using MacPorts you can install the client with:
sudo port install mysql57
You also need to select the installed version as your mysql
sudo port select mysql mysql57
The server is only installed if you append -server to the package name (e.g. mysql57-server)

The easiest way would be to install mysql server or workbench, copy the mysql client somewhere, update your path settings and then delete whatever you installed to get the executable in the first place.

The mysql client is available in macOS ports. If you don't have this excellent third party package manager already installed, it is available from here: https://www.macports.org/
Once you have installed macports, open a terminal and make sure everything is up to date:
sudo port selfupdate
There are multiple different versions of MySQL and mariadb (community fork of MySQL) available in the ports repos. List available versions using the following command:
port search 'mariadb*'
I recommend choosing mariadb over mysql as it is, mostly, a drop in replacement (https://mariadb.com/kb/en/mariadb-vs-mysql-compatibility/) and has excellent community support.
If applicable, choose which version of mariadb you want (a list of versions of mariadb is available here: https://downloads.mariadb.org/mariadb/+releases/). If you're not bothered, install the default version:
sudo port install mariadb
Mariadb (including the mysql-compatible command line client) is now available on your system. On my system, the CLI client resides in the following location:
$ /opt/local/bin/mysql --version
/opt/local/bin/mysql Ver 15.1 Distrib 5.5.68-MariaDB, for osx10.15 (x86_64) using readline 5.1
It's obviously a bit inconvenient to type out the full path, /opt/local/bin/mysql each time you want to use the client. Ports has already thought of this problem. To view available versions of mysql on your system, run:
$ port select mysql
Available versions for mysql:
mariadb (active)
none
Choose one from the list. For example, to use mariadb as the default mysql client:
sudo port select mysql mariadb
Now open a fresh terminal window and you should be able to start the mariadb mysql CLI client:
mysql -h <hostname> -u <username> -p

if you need a lighter solution i recommend mysql-shell, install using the command below.
brew cask install mysql-shell
To start after installation type mysqlsh.

Related

Install MySQL v8 in Google Colab. Service is not starting. Not recognised

I have been successfully installing and using MySQL V5.7 in Google Colab (with Ubuntu 18.04) for quite some time. However trying to install MySQL V8 has repeated failed. I have used the following sequence of commands ..
!apt update
!apt upgrade
#!wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.11-1_all.deb
!wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
!dpkg -i mysql-apt-config_0.8.*
!sudo apt update
!sudo apt install mysql-server
During the install, I provide the root password and have used both the strong password option as well as the legacy authentication. Everything goes fine upto this point and even the following command
!mysqld --version
returns the correct version
/usr/sbin/mysqld Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)
After this things go wrong! The MySQL service should have started but it hasn't
!mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
and when I try to start it, it is not recognised ( neither mysql nor mysqld)
!sudo service mysqld start
mysqld: unrecognized service
in fact, even this fails
!systemctl status mysql
System has not been booted with systemd as init system (PID 1). Can't operate.
What am I doing wrong? or what else should I do? or is it that for some reason, Google Colab with Ubuntu 18.04 does not support MySQL V8
No action required ... just this will do
!apt update > null
!apt -y install mysql-server -V
!/etc/init.d/mysql restart
then check
!mysql --version
mysql Ver 8.0.31-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
earlier this used to show Ver 5.7!
Now, with this we can now use CTE, recursion and Windows functions of v8
Check with sudo service mysql start or sudo start mysql once.
Another thing is that google colab instance might not use the system init system at all. That's why it's resulting in System has not been booted with systemd as init system. Check with the sys-v init system once. Its commands look like service service_name start. The same thing happens when trying to start services in WSL.

How to run MYSQL in MINGW64 on Windows10?

I really liked the environment of MINGW64 on Windows10 since Python, TMUX and VIM come in handy through Pacman. However, there's no MYSQL package available for MINGW64. How could I run/install MYSQL in MINGW64 on Windows10?
I found a little trick since I was not successful in building the package for MingW64.
I downloaded the mariadb-10.4.11-winx64.msi from the mariadb download site and install the usual way. Added the MariaDB in the path:
export PATH=$PATH:''C:\Program Files\MariaDB 10.4\bin'
Install winpty using pacman:
pacman -Syu winpty
Enter winpty mysql -u root -p:

How can i remove instance of mysql from brew info mysql

I am trying to remove mysql from my macbook pro to start from fresh.
I have followed guides on how to remove all instances and files of mysql, however if i run
brew info mysql
I still get info pertaining to mysql 8.0 as follows:-
mysql: stable 8.0.12 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
Conflicts with:
mariadb (because mysql, mariadb, and percona install the same
binaries.)
mariadb-connector-c (because both install plugins)
mysql-cluster (because mysql, mariadb, and percona install the same
binaries.)
mysql-connector-c (because both install MySQL client libraries)
percona-server (because mysql, mariadb, and percona install the same
binaries.)
Not installed
From: https://github.com/Homebrew/homebrew-
core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✘
==> Requirements
Required: macOS >= 10.10 ✔
==> Options
--with-debug
Build with debug support
--with-embedded
Build the embedded server
--with-local-infile
Build with local infile loading support
--with-memcached
Build with InnoDB Memcached plugin
--with-test
Build with unit tests
==> Caveats
We've installed your MySQL database without a root password. To secure
it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Analytics
install: 66,127 (30d), 215,889 (90d), 794,987 (365d)
install_on_request: 61,289 (30d), 185,026 (90d), 647,998 (365d)
build_error: 444 (30d)
How can i completely remove this? Thank you for any help!
mysql is already uninstalled. See these lines in the middle of your output:
Not installed
From: https://github.com/Homebrew/homebrew-
core/blob/master/Formula/mysql.rb
Homebrew is fetching this information on mysql's dependencies and usage remotely from GitHub. I do not have mysql installed either and get the same output when I run brew info mysql. If you try running mysql from the command line, you should get -bash: mysql: command not found.

Debian 9 how to install MariaDB without MySQL nameing?

I'm going thru this instrucion, trying to keep data collected from DHT22 temperatur/humidity sensor on my RaspberryPi2 with Raspbian (Debian9) onboard.
But when it comes to install and use of the DB server, when i try to install MySQL, apt-get installs MariaDB.
From this and this link I know why, but i don't want to use MySQL name in my later scripts if my procedures really uses MariaDB.
So please tell my how change below commands to instal MariaDB directly, and login to DB interface without using MySQL name:
sudo apt-get install mysql-server python-mysqldb
mysql -u root -p -h localhost
With those commands MariaDb is the default install for Debain 9. So all you need to do now is
apt-get install phpmyadmin and mysql_secure_installation. Then you can login and access the interface at localhost/phpmyadmin

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 executable 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, 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??
A MySQL server is not a MySQL client.
Check if MySQL is running by executing this command:
ps aux | grep mysql | grep -v grep
And install the MySQL client:
sudo apt-get install mysql-client # Or your distribution command
If you have MySQL server up and running on your server, it does 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 you run binaries for another architecture.
For example, if you run a 32-bit executable on 64-bit system you will get an error message like "command or file not found", even if the binaries are actually present!
Now mysql-client has changed to default-mysql-client.
Hence the command:
sudo apt-get install default-mysql-client
Although MySQL is running, if you are not able to connect to the server using the 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.
In order to get MySQL CLI working or to access the mysql command from anywhere, there are a set of steps to be done to add it to the $PATH variable.
First, open a terminal, and run the following command
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
Then to reload the 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
You sometimes need to install MySQL on the local machine as well. That means, if you have a host running a MySQL Docker container, the strange thing happened to me that I needed to install mysql-server on the host as well, not only in the container.
The reason was that there was a shell script that needed to check the right database name from a query. In your case, it might be something different. On your host machine (which might even be your local computer, depending the your setup), if on Linux, try:
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