Access mysql for MAMP from command line - mysql

I have been learning Ruby on Rails and have been using the command line successfully to view and edit the database (using the mysql command).
I am now using MAMP and trying to install Wordpress. It appears that it is using a "different" mysql. I.e., databases I create via the command line aren't viewable in MAMP's phpmyadmin, and vice versa.
How can I access MAMP's mysql via the command line? I'm guessing that I need to specify the host when logging in with the mysql command, but I'm not sure what to put there. Since phpmyadmin exists at localhost:8888/phpMyAdmin, I tried using mysql -h localhost:8888 -u root -p, but that didn't work (error: Unknown MySQL server host 'localhost:8888').

MAMP installs it's own MySQL which means that you now have two MySQL instances installed on you machine.
try typing this in your terminal
/Applications/MAMP/Library/bin/mysql

You can also add this to your a bash_profile so you don't have to write /Applications/MAMP/Library/bin/mysql each time by running in terminal :
sudo vi ~/.bash_profile
and adding
alias mysql="/Applications/MAMP/Library/bin/mysql"
Then, from terminal you can run : mysql -uroot -proot notice theres no space for this to work.

Related

Not able to run mysql 8.0.12 as root on macOS

I have downloaded macOS 10.13 (x86, 64-bit), DMG Archive and install it on my Mac(10.13.6) but while accessing it in terminal it's not taking root password which I have set during the installation process.
I have checked system preference MySQL is running and trying to access MySQL by below command, though it's asking for the password but not taking it after trying it, its giving below error
sudo /user/local/mysql -u root -p
error : sudo: /user/local/mysql: command not found
You didn't install mysql there. Double-check where it's actually installed. You'll probably be able to use plain old mysql as the command name.

Why does it show, "Wrong Password", when I am trying to start mysql from the terminal?

I was trying to start mysql from my terminal using the command "sudo start mysql", after which it asks for the password, which when I am providing, it says "wrong password". But, I know, it's the right one, as I am using the same password to connect with workbench, and it's working fine there.
The command sudo start mysql is telling your linux environment to start the mysql service using upstart.
When you use the sudo command in your terminal you are telling the computer that you wish to run the start mysql command as root. It asks you for your user credentials for that computer (not your MySQL credentials).
You may have the same username created inside your MySQL database, but it may not have the same password as your Linux user.

Joomla installation prevention with a mysql warning

I seem to keep encountering an installation issue for installing Joomla on Linux. Although without Joomla I can still independently create/modify sql queries accessing mariadb with mysql -u root -p then starting lampp with sudo /opt/lampp/lampp start and website building as soon as I xdg-open /opt/lampp/htdocs, I am still unable to figure out how to by pass the Warning I keep getting when I try to install Joomla by creating that Admin account installation process.
The warning message I keep getting is: `The installer was not able to connect to the MySQL. Please make sure MySQL is running and introduce a valid password to connect to the MySQL server.
I was assuming the MYSQL was automatically running since I am able to create sql fields and input them from mariadb... and also the fact that when I run: mysqladmin -u root -p status because I still see Uptime, but I do not think that is the case.. so I am not really sure...

Cygwin connecting to MySQL: Can't connect to local MySQL server through socket '/var/run/mysql.sock'

I just installed MySQL 5.5.27 on WinXP. When I open a command prompt (Start -> Run, and type "cmd"), I can access MySQL by running "mysql -u root -p". However, when I open a Cygwin terminal and try the same thing, I get this error
$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
Indeed, there is no "/var/run/mysql.sock" file.
If you specify the host on the command line, this issue should go away:
mysql -u root -p -h 127.0.0.1
You can also create a my.ini that mysql will use:
echo [client] >c:\my.ini
echo user=root >>c:\my.ini
echo host=127.0.0.1 >>c:\my.ini
Then you can just type:
mysql -p
You can even add the password:
echo password="abracadabra" >>c:\my.ini
Then, just type:
mysql
and you're in!
See also https://serverfault.com/questions/337818/how-to-force-mysql-to-connect-by-tcp-instead-of-a-unix-socket
Try adding this to your command:
-h 127.0.0.1
The problem is that the mysql client default host is localhost, and it treats localhost specially, using a unix socket, which is accessed via that file, but your server may not be configured to listen on the unix socket.
However, if you access the same server via the loopback IP 127.0.0.1 it will use a TCP socket instead of the unix socket and (assuming the server is online) it should work.
Just to save few keystorkes,
Add following alias to your ~/.bashrc file.
alias mysql='mysql -u root -h 127.0.0.1'
After adding this, You can just type "mysql" in your terminal & there you go right inside mysql.
As most of people mentioned here - one of the solutions will be to use aliases. Don't like them to be honest because they are preventing me learning some really nice Linux commands :) It's just a joke. But the best way for you, as I think, will be to locate a ~/.bashrc file located in your home directory and put there:
alias mysql="mysql -h 127.0.0.1"
Don't forget that you have to restart your session in order for this solution to work or you may type bash command at the same terminal session - it will reload all your bash settings. Good luck!
P.S. I suggest you to close all other terminal windows before editing .bashrc because you may just got a read-only file. I had such issue under Win7x64
I successfully installed MySQL in Cygwin on my PC according to Rafael Hart. I created a database and performed some queries and everything worked great.
The next day when I tried logging into MySQL, I got the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (111 "Connection refused")
Apparently, when you shutdown your PC, the services also get shutdown and do not restart on boot.
To fix the problem, I typed the following command to restart the mysqld service:
$ mysqld_safe &
Then everything started working.
Here's how to run MYSQL from cygwin
Go here:
https://cygwin.rafaelhart.com/setting-up-mysql-on-cygwin/
To begin MySQL setup run the following:
mysql_install_db
Run mysql - you'll get a firewall alert from windows if you have it active.
mysqld_safe & Immediately following that, it would be wise to run the following:
mysql_secure_installation

How to use phpmyadmin mysql database using terminal in ubuntu 10.4?

Can any one help me to use phpmyadmin mysql database through terminal.
I am using ubuntu 10.4.
I guess the command like this /opt/var/usr/ mysql. I'm not sure about it.
In terminal just type:
mysql -u username -p
and afterwards you'll be prompted for your password.
Normally MySQL is added to /bin/ so no need to explicitly give a path to it.
Answer:
The Below command used to access phpmyadmin mysql database though terminal
/opt/lampp/bin/mysql -uroot -ppassword