Access MAMP's MySQL from Terminal

前端 未结 7 1210
时光说笑
时光说笑 2020-12-07 13:34

I want to practice using SQL instead of phpMyAdmin.

How do I log into MAMP\'s MySQL from the terminal?

相关标签:
7条回答
  • 2020-12-07 14:12

    I'm assuming the version of MAMP you're using installs itself in /Applications/MAMP. First make sure via the MAMP console that the Mysql server is on. Then connect like this from command line:

    /Applications/MAMP/Library/bin/mysql -uUsername -pPassword
    

    Obviously replace Username and Password. BTW, there is no space between -u and the Username or -p and the Password.

    Good Luck learning Mysql the old fashion way!

    0 讨论(0)
  • 2020-12-07 14:13

    If you just want to type:

    mysql -u Username -p
    

    You can create an alias in your ~/.bash_profile in older OSX versions this file was called ~/.profile so best check first with

    ls -la ~/
    

    If one of those files exist, edit that file. Else, create a new one with what ever editor you like (here I do it with nano and have a ~/.bash_profile file)

    sudo nano ~/.bash_profile
    

    insert following line

    alias mysql=/Applications/MAMP/Library/bin/mysql
    

    Save the file and quit nano with CTRL + X and then type Y and enter

    Then you need to type

    source ~/.bash_profile
    

    Now you can use

    mysql -u root -p
    
    0 讨论(0)
  • 2020-12-07 14:13

    I had to do a little modification, first go to the bin folder

    cd /Applications/MAMP/Library/bin/
    

    then to run mysql file a had to execute

    ./mysql -uUSERNAME -pPASSWORD
    

    The reason was that: Running an executable in Mac Terminal

    0 讨论(0)
  • 2020-12-07 14:21

    This line works for me:

    /Applications/MAMP/Library/bin/mysql -uroot -p
    
    0 讨论(0)
  • 2020-12-07 14:34

    If you want to do it on Windows type:

     c:/MAMP/bin/mysql/bin/mysql.exe -u username -p dbname < data.sql
    
    0 讨论(0)
  • 2020-12-07 14:37

    Just simply create a symbolic link to the MAMP mysql.

    sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql
    

    Then you can easily call it from any directory like this:

    mysql -uUsername -pPassword
    
    0 讨论(0)
提交回复
热议问题