21

I am trying to access mysql from my mac's terminal.

I have tried just typing

mysql -u root -p

(and Enter, but that does not exist..)

This is what I have managed to do/located so far:

Williams-iMac:mysql noName$ cd /Applications/xampp/xamppfiles/var/mysql/mysql

Williams-iMac:mysql noName$ ls

This is what is located there.

columns_priv.MYD        help_relation.frm       slow_log.CSV
columns_priv.MYI        help_topic.MYD          slow_log.frm
columns_priv.frm        help_topic.MYI          tables_priv.MYD
db.MYD              help_topic.frm          tables_priv.MYI
db.MYI              host.MYD            tables_priv.frm
db.frm              host.MYI            time_zone.MYD
event.MYD           host.frm            time_zone.MYI
event.MYI           ndb_binlog_index.MYD        time_zone.frm
event.frm           ndb_binlog_index.MYI        time_zone_leap_second.MYD
func.MYD            ndb_binlog_index.frm        time_zone_leap_second.MYI
func.MYI            plugin.MYD          time_zone_leap_second.frm
func.frm            plugin.MYI          time_zone_name.MYD
general_log.CSM         plugin.frm          time_zone_name.MYI
general_log.CSV         proc.MYD            time_zone_name.frm
general_log.frm         proc.MYI            time_zone_transition.MYD
help_category.MYD       proc.frm            time_zone_transition.MYI
help_category.MYI       procs_priv.MYD          time_zone_transition.frm
help_category.frm       procs_priv.MYI          time_zone_transition_type.MYD
help_keyword.MYD        procs_priv.frm          time_zone_transition_type.MYI
help_keyword.MYI        servers.MYD         time_zone_transition_type.frm
help_keyword.frm        servers.MYI         user.MYD
help_relation.MYD       servers.frm         user.MYI
help_relation.MYI       slow_log.CSM            user.frm

But i still don't know how to access the mysql, so that i can create a new database (without doing it i phpmyadmin). I have created a new database in phpmyadmin though, just to try enter:

mysql -u root -p (my_phpmyadmin_created_database)

..but without any success.

8
  • Is there a mysql/bin directory anywhere in your xampp install. find -name 'mysql' in that dir may also help. Commented Dec 15, 2012 at 14:56
  • Tried indented 4 spacecs to get this to look nice, but it does not seem to work.. this is what i got when i tried find -name 'mysql': Williams-iMac:~ noName$ find -name 'mysql' (AND PRESSED ENTER HERE I DID) find: illegal option -- n usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] Commented Dec 15, 2012 at 15:13
  • Ah, path is required there apparently. find . -name 'mysql' in the xampp dir it is then. Commented Dec 15, 2012 at 15:23
  • Williams-iMac:~ noName$ cd /Applications/xampp/ Williams-iMac:xampp noName$ find . -name 'mysql' (AND ENTER) Will generate.........:./xamppfiles/bin/mysql ./xamppfiles/lib/mysql ./xamppfiles/lib/perl5/site_perl/5.10.1/darwin-2level/auto/DBD/mysql ./xamppfiles/lib/perl5/site_perl/5.10.1/darwin-2level/DBD/mysql ./xamppfiles/licences/mysql ./xamppfiles/share/mysql ./xamppfiles/var/mysql ./xamppfiles/var/mysql/mysql find: ./xamppfiles/var/mysql/widget_corp: Permission denied Commented Dec 15, 2012 at 15:30
  • So, ./xamppfiles/bin/mysql is your binary which you can use, or you might want to add that ./xamppfiles/bin/ to your $PATH Commented Dec 15, 2012 at 15:32

9 Answers 9

60

/Applications/xampp/xamppfiles/bin/mysql -u root -p

Worked like a charm!

Thanks to user: Wrikken!

Sign up to request clarification or add additional context in comments.

1 Comment

works perfectly great. Thumbs up!
14

I'm just a new xampp user. I am also trapped by this question. Yes, the right directory is

/Applications/XAMPP/xamppfiles/bin/(the newest xampp is uppercase)

but when you connect to db, you should type

./mysql -u root -p (if there's password),

not input

mysql -u root -p...   

directly, it wordked successfully on my macbook pro.

Comments

12

I usually do this to activate php and mysql from terminal with XAMPP 1.7.3(and probably above) on Mac

 1. Go to Terminal
 2. Enter which php: If it says /usr/bin/php, then proceed to 3.
 3. Enter sudo nano ~/.bash_profile (or sudo vim ~/.bash_profile if you know how to use it)
 4. Then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
 5. Ctrl - O then enter to save, then ctrl - X to exit.
 6. Type cd ~
 7. type . .bash_profile
 8. Restart terminal.
 9. Enter which php: If you did it right, it should be the same as the path in #4.

2 Comments

@Moe. You might have got an answer now on how it works, but for those who didn't, what Ricardo did is that he provided the path of the commands to 'bash_profile' which makes the terminal able to execute the commands from anywhere (any directory). He registered the path of php and mysql so terminal knows their absolute location even if you don't provide it in the command like /mypath/somepath/mysql.
Also worth noting that sometimes or if the ~/.bash_profile is not available, use ~/.profile.
4

if the xampp is install in your mac book just go the file path of cd /Applications/XAMPP/bin/

./mysql -u root -p

than it will ask for password if set than type else enter

mysql is started now !!!!!!!!

1 Comment

Solved it finally
4
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start

1 Comment

Please provide some context and a short explanation as to why and how this works
3

In macOS Monterey

  • open terminal and run following command

    sudo nano /etc/paths

  • then after the bottom line add following path

    /Applications/XAMPP/xamppfiles/bin

  • now press control+x to save

  • then press y to confirm save

  • then press enter

  • restart the terminal

now mysql is working

Comments

1

I had to use open command for me to work.

e.x.

open /App/Applications/xampp/xamppfiles/bin/mysql

Comments

0

Nice feature on Mac is to open terminal and go to preferences. Hit profiles tab and create a new profile. under shell type the path to MySQL and enter in everything as you would when going the long way. Ex:

/Applications/XAMPP/xamppfiles/bin/mysql --user=root --password=

Just add your info on the path above. close the preference window and go to FILE and hit new window. Chose your profile. I named mine MySql. Thats it.

Comments

0

I used this to access phpmyadmin mysql database though terminal

/opt/lampp/bin/mysql -uroot -ppassword

then

USE dbname

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.