开发者

Unable to start MySQL from the terminal

I am quite new to the Macintosh, I have Mac OS 10.6 installed.

I downloaded the mysql-5.4.3-beta-osx10.5-x86.dmg file and installed all the files properly.

I have got MySQL server started in system preferences.

Now I want to access MySQL from the terminal but I am unable to do it.

I have tried mysql -u root.

It shows "-bash: mysql: command not fo开发者_如何学Cund".

How can I make it work?

Is there any tool like phpMyAdmin for Mac?


It sounds like you have a path problem in the current shell. Some steps to check/do are:

  • Can you get to the MySQL prompt from the installed location ? Let's assume that you have installed MySQL in /usr/local/mysql. Then if you change directory (cd /usr/local/mysql/bin) you should be able to execute the mysql command: ./mysql

  • Check the path settings via env command in your current shell. What you are looking for is the value of PATH where you want to have something along the lines of: PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin..... with some reference to mysql's installled path

  • Reset your current path to include /usr/local/bin. This can be done in the instance of the current shell via export PATH=/usr/local/mysql/bin:/usr/local/bin:$PATH

  • Test that you can then access the mysql binary from any path on your system.

In terms of the tools for accessing MySQL you can take a look at:
- SequelPro
- MySQL Tools


To expand on lutz's (rather brusque) answer, if you look near the bottom of the Mac OS X installation manual you'll see the lines

alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin

These are commands that tell your shell, bash, "when I type mysql I really mean to execute /usr/local/mysql/bin/mysql." You can add these commands to the end of the file .bash_profile in your user's home directory (using echo in conjunction with >>~/.bash_profile or similar) so that they get run every time you launch a shell.

Better yet, use the same file to change your PATH environment variable. Doing something like

export PATH="/usr/local/mysql/bin:${PATH}"

will tell the shell that any executable files found in that directory (like mysql, mysqladmin, and so forth) should be executed when you type just their names, rather than the full path.


I had the same problem. I use MAMP. Just typed "/Applications/MAMP/Library/bin/mysql" instead of "mysql", and I got the problem resolved. Hope that helps.


Open your terminal and type

> nano .bash_profile

add the followin line

export PATH="/usr/local/mysql/bin:${PATH}"

Save the file and re open the terminal, you should be able to write

mysql -u root -p 

and login into mysql

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜