Mac install and open mysql using terminal - mysql

I downloaded the mysql dmg file and went through the wizard to run. Done. I have also started mysql server under system preferences.
The purpose of me doing this is to work through the exercises of my SQL text book. The terminal commands are new to me but I think once I can actually get started, working through the exercises should be OK.
From researching the web the various blogs tell me to navigate to to the mysql folder in the terminal:
/usr/local/mysql
Fine. Then it gets a little less clear as nearly each article has a different set of instructions on how to proceed. I was fiddling with it yesterday and was prompted for a password - what is the default mysql password?
Could someone give me the steps to get up and running with mysql via the terminal?

(Updated for 2017)
When you installed MySQL it generated a password for the root user. You can connect using
/usr/local/mysql/bin/mysql -u root -p
and type in the generated password.
Previously, the root user in MySQL used to not have a password and could only connect from localhost. So you would connect using
/usr/local/mysql/bin/mysql -u root

open terminal and type
sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
then close terminal and open a new terminal and type
mysql -u root -p
hit enter, and it will ask you for password
I have found this solution on https://teamtreehouse.com/community/says-mysql-command-not-found
now to set new password type
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';

In the terminal, I typed:
/usr/local/mysql/bin/mysql -u root -p
I was then prompted to enter the temporary password that was given to me upon completion of the installation.

In MacOS, Mysql's executable file is located in /usr/local/mysql/bin/mysql and you can easily login to it with the following command:
/usr/local/mysql/bin/mysql -u USERNAME -p
But this is a very long command and very boring, so you can add mysql path to Os's Environment variable and access to it much easier.
For macOS Catalina and later
Starting with macOS Catalina, Mac devices use zsh as the default login shell and interactive shell and you have to update .zprofile file in your home directory.
echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.zprofile
source ~/.zprofile
mysql -u USERNAME -p
For macOS Mojave and earlier
Although you can always switch to zsh, bash is the default shell in macOS Mojave and earlier and with bash you have to update .bash_profile file.
echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.bash_profile
source ~/.bash_profile
mysql -u USERNAME -p

install homebrew via terminal
brew install mysql

This command works for me:
./mysql -u root -p
(PS: I'm working on mac through terminal)

In terminal
sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
Close that and open new terminal
mysql -u root -p
Give your password

For mac OS Catalina :
/usr/local/mysql/bin/mysql -uroot -p
This will prompt you to enter password of mysql

You can simply type in Terminal
brew services start mysql
if you installed mysql via brew on mac

If you have your MySQL server up and running, then you just need a client to connect to it and start practicing. One is the mysql-client, which is a command-line tool, or you can use phpMyAdmin, which is a web-based tool.

This command works for me:
Command:
mysql --host=localhost -uroot -proot

try with either of the 2 below commands
/usr/local/mysql/bin/mysql -uroot
-- OR --
/usr/local/Cellar/mysql/<version>/bin/mysql -uroot

Related

how to connect to a mysql url from mac using mysql-client

I used `brew install mysql-client' and it installed the client but I have no access to manual help on this. What is the way to connect with a url mysql://db.dev.dev.ms-df-cloudrdbms.glb.us.net:3306/cx_cortex for instance ? Do I have to also install mysql server to connect or is there a client?
Mysql client command is quite easy to use:
mysql -h mysqlhost.mycompany.com -u root -p db_name
-h host
-u user
-p (input password by typing it or in the command line)
For help, you can try:
mysql --help

Raspberry-Pi 3: LAMP Web Server with WordPress

I want to build a LAMP Web Server with WordPress using a Raspberry-Pi 3 and I have followed this tutorial:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress
I am having some problems with MySQL installation, because using the command
$ sudo apt-get install mysql-server php-mysql -y
I can't select the root password, as written in the tutorial. Then, I am not able to enter the MySQL database with command
$ mysql -uroot -ppassword
neither using
$ mysql -uroot -p
The only way to enter the database is to use (without any password)
$ sudo mysql -uroot
In the last step of tutorial, when I have to select the database connection details, I don't know which password to use.
Can anyone help me?
Thank you!
There are two "roots".
The password for the OS's root is used for sudo.
The password for MySQL's root is used for mysql -u root -p.
There should be no need for sudo mysql .... But when you do it, first the OS has control and either remembers that you are sudo, or prompts something like
[sudo] password for root:
Then mysql gets control and sees the -p, so prompts you:
Enter password:
During the setup, were you ever asked to create a mysql root password? If not, then mysql -uroot would get into mysql without a password. You should create a password then for security.
This is possibly caused by the change that Debian did to MariaDB. They enabled the UNIX socket authentication plugin by default for newer versions. This would explain why no password is required.
If you want to enable password authentication, you could create a separate root user account. This appears to be required to complete the tutorial.
CREATE USER 'root'#'127.0.0.1' IDENTIFIED BY 'my-password';
This creates the user root with the password my-password which you can then add to the WordPress configuration.

Mysql 5.7.17 root password forgotten / no access to mysql command line on Mac

I downloaded MySQL 5.7.17 for Mac and installed it. I can start and stop the SQL server from my Preferences > MySQL. It is shown as an instance on port 3306 from Workbench so all that seems fine. However, during install toward the end a pop-up window listed a password I was supposed to use. I assumed it would be promptly needed so copied on the clipboard. Few mins later having not been prompted for it yet, I copied something else in the clipboard thus losing it.
I have been trying to get some sort of client of mysql command line so I can enter sql commands, however there is no "Application" installed to use to access the server. I have scoured the MySQL documentation and Stack and beyond, and searched for how to get the password reset, and a mysql client/command line, but all the articles seem to assume you already have access to a "MySQL terminal"/"command line". I only have access to my normal Mac Terminal, and most commands in the normal Terminal window either fail or require the password I don't have, for example:
$ mysqld --skip-grant-tables
-bash: mysqld: command not found
$ mysql -u root -p
-bash: mysql: command not found
$ sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
Password: (this is probably the password I was given that got overwritten? When I try the admin password of the machine it sends me back to the prompt)
$ sudo mysqld_safe --skip-grant-tables (after I'd stopped the server)
sudo: mysqld_safe: command not found
Can somebody please help me figure out how to get to a "MySql Terminal" and if I need this password that got overwritten, how to reset it? (it seems like uninstalling MySQL to repeat the steps and this time take better care of the password is actually horrendously difficult / no uninstall protocol?).
Thank you so very much.
--- Update: I used the How To Uninstall suggested by Josh M and then re-installed. This time I saved the password (so far, not sure how / where I need to use it). However, I must really be missing something b/c I still can't get access to mysql.
/usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'Robert'#'localhost' (using password: NO)
Then I did $ export PATH=$PATH:/usr/local/mysql/bin but I still get ERROR 1045.
Try these set of commands
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
/usr/local/mysql/bin/mysql
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'YOUR_NEW_PASSWORD';
EXIT;
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start
$ mysql -u root -p
$ Enter Password: 👉🏻 ENTER_YOUR_NEW_PASSWORD_HERE 👈🏻
And enjoy 🎉
There's a tutorial for resetting passwords here: https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
Your MySQL command line interface (cli) is probably at:
/usr/local/mysql/bin/mysql
Honestly it might be better to reinstall. There's an SO on that: How do you uninstall MySQL from Mac OS X?

mysql shell line in windows doesn't work

i have installed mysql community, but when i write the comand mysql -u root -p windows says the command not exist...how can i resolve it?

Cannot log in to user root

I've gotten a new laptop and after installing the newest version of xampp I cant log in to mysql as -u root.
I made sure that mysql is turned on in xampp.
Lines I've tried
cd\xampp\mysql\bin>mysql.exe -u root -p
cd\xampp\mysql\bin -u root -p
I've also tried starting mysql.exe directly and couldnt log in with similair commands.
The default setup of Xampp does not set a root password in mysql.
Try connecting without the -p. c:\xampp\mysql\bin\mysql.exe --user=root
The following is from the FAQ - https://www.apachefriends.org/faq_windows.html
Is XAMPP production ready?
Here a list of missing security in XAMPP:
The MySQL administrator (root) has no password.