在 OS X 中使用 XAMPP 时如何访问 mysql 命令行工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3354046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:41:24  来源:igfitidea点击:

How can I access the mysql command line tool when using XAMPP in OS X?

mysqlmacosxampp

提问by Jim

I've got a vanilla install of XAMPP in OS X. How can I access the mysql command line tool? I've tried typing "mysql" at the command line, and it spits back "-bash: mysql: command not found".

我在 OS X 中安装了 XAMPP。如何访问 mysql 命令行工具?我试过在命令行输入“mysql”,它会回吐“-bash: mysql: command not found”。

回答by Pablo Santa Cruz

XAMPP is installed in Mac OS X in the following directory:

XAMPP 安装在 Mac OS X 中的以下目录中:

/Applications/XAMPP/

You can look what's inside that directory and run mysqlcommand line tool providing the full path to it:

您可以查看该目录中的内容并运行提供完整路径的mysql命令行工具:

$ /Applications/XAMPP/xamppfiles/bin/mysql

If you need, you can modify your PATHenvironment variable to include XAMPP binaries and you won't need to specify the whole path all the time.

如果需要,您可以修改PATH环境变量以包含 XAMPP 二进制文件,并且不需要一直指定整个路径。

回答by Kumi Yare

  1. Open your .profile file in Mac. This can be done by entering the terminal and typing

    pico ~/.profile
    
  2. Add the following line to your ./profile file. Replace the path where you installed Xampp, however by default this is the route and should work:

    export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH
    
  3. Open a new terminal window (Recommendation is to quit all terminal windows and then reopen) and type:

    mysql
    
  1. 在 Mac 中打开您的 .profile 文件。这可以通过输入终端并键入来完成

    pico ~/.profile
    
  2. 将以下行添加到您的 ./profile 文件中。替换安装 Xampp 的路径,但默认情况下,这是路径并且应该可以工作:

    export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH
    
  3. 打开一个新的终端窗口(建议退出所有终端窗口,然后重新打开)并键入:

    mysql
    

That is all, isn't easy!!

就是这样,不容易!!

回答by Kumi Yare

Before using the mysqlcommand, make sure that you start up the server first by running

在使用该mysql命令之前,请确保首先通过运行来启动服务器

$ mysql.server start

Then you will be able to use the commands mysqladminand mysql.

然后您将能够使用命令mysqladminmysql.

To shut it down, run

要关闭它,请运行

$ mysql.server stop

and to restart just use

并重新启动只需使用

$ mysql.server restart

Very intuitive.

非常直观。

回答by Mahabub Rahman

Open terminal and Follow this bellow step to add mysql to your mac environmental variable

打开终端并按照以下步骤将 mysql 添加到您的 mac 环境变量中

step 1:

第1步:

sudo nano ~/.bash_profile

step 2:

第2步:

export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH

save it by control+x and then y and hit return. That's it!! now close the terminal and reopen

通过 control+x 然后 y 保存它并按回车键。就是这样!!现在关闭终端并重新打开

mysql --version

this will tell you which MySQL version you are using with xampp

这将告诉您 xampp 使用的是哪个 MySQL 版本