MacOS下配置mysql server 和环境变量实现命令行调用的教程

博主是在校大二学生,粗浅的把自己在mac上摸索出的经验整理一下

这两天刚把学校布置在oracle平台上的sql命令实验做完,开始着手做数据库课程设计

众所周知,学校的老师一般都会认为你们用的是windows系统(此处省略一万句mmp),所以macos上安装软件都必须自己摸索

首先要建立数据库,我选择了先下载mysql 搭环境 

百度搜索 mysql 第一项就能找到

进入mysql的官网,找到download界面

我们要下载的是mysql server 的commuity版本

选择图中出现的版本下载即可

当然可能版本没有很重要,博主选择的是macOS 10.14 (x86, 64-bit), DMG Archive版本 当前最新的版本号是8.0.13

如上图,如果是Windows系统的小伙伴,可能就不太一样了

下载下来文件以后,点开.dmg文件运行 会出现一个.pkg文件 点开运行即可

接下来是本文的重点所在 我们可以点开苹果的finder 看一下我们的mysql文件下载在哪里了

在我们的Macintosh HD下的/usr/local目录下有两个文件 一个是mysql 一个是mysql-8.0.13-macos10.14-x86-64

比对了一下其实这两个文件在我看来是存储了相同的内容,也不敢删除哪一个,万一不好用了就比较麻烦

可以对比一下,可以发现你们电脑里的mysql文件夹下没有my.cnf 

这是mac下mysql的配置文件 Windows下应该是叫my.ini 

为什么要添加这个文件呢?

因为博主在终端想要调mysql命令的时候,比如在主用户目录下输入$mysql -u root -p的时候

总是给我报command not found 的错误

然后一个简单的方法是在命令行里创建一个一次性链接

输入命令:

$ln -s /usr/local/mysql/bin/mysql /usr/bin

一般来说这时候再去输入$mysql -u root -p 就会跳密码输入提示了

但是博主脸比较黑   命令行提示我:

ln: /usr/bin/mysql: Operation not permitted

那没事 ,我们用sudo提高一下权限 输入命令:

$sudo ln -s /usr/local/mysql/bin/mysql /usr/bin

然后输入密码 发现还是不行 接着给我 ln: /usr/bin/mysql: Operation not permitted

那么没办法 只好采用权宜之计 先用alias命令改个名用一下吧 输入命令:

$alias mysql=/usr/local/mysql/bin/mysql 

这时候不管脸再怎么黑,都应该可以输入mysql命令了 可以先用这个方法测试一下

但是难道我每次登陆都去输入一个这个命令吗? 

百度搜索了一下,发现好多博主都给出了这样的解答

 

 

输入:

cd  /usr/local/mysql

回车执行

然后输入:

sudo vim .bash_profile

回车执行

需要输入root用户密码。sudo是使用root用户修改环境变量文件。

进入编辑器后,我们先按"i”,即切换到“插入”状态。

在文档的最下方输入:

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

然后按Esc退出insert状态,  

:wq

实现保存

however 我改过之后也还是不行 可能有些小伙伴可以用这个方法实现

我选择了自己再加一个配置文件

1.在 /etc 新建 my.cnf 文件

sudo vim my.cnf

2.同样的方法,将如下配置内容写入到文件中

# Example MySQL config file for medium systems.  
  #  
  # This is for a system with little memory (32M - 64M) where MySQL plays  
  # an important part, or systems up to 128M where MySQL is used together with  
  # other programs (such as a web server)  
  #  
  # MySQL programs look for option files in a set of  
  # locations which depend on the deployment platform.  
  # You can copy this option file to one of those  
  # locations. For information about these locations, see:  
  # http://dev.mysql.com/doc/mysql/en/option-files.html  
  #  
  # In this file, you can use all long options that a program supports.  
  # If you want to know which options a program supports, run the program  
  # with the "--help" option.  
  # The following options will be passed to all MySQL clients  
  [client]
  default-character-set=utf8
  #password   = your_password  
  port        = 3306  
  socket      = /tmp/mysql.sock   
  # Here follows entries for some specific programs  
  # The MySQL server  
  [mysqld]
  character-set-server=utf8
  init_connect='SET NAMES utf8
  port        = 3306  
  socket      = /tmp/mysql.sock  
  skip-external-locking  
  key_buffer_size = 16M  
  max_allowed_packet = 1M  
  table_open_cache = 64  
  sort_buffer_size = 512K  
  net_buffer_length = 8K  
  read_buffer_size = 256K  
  read_rnd_buffer_size = 512K  
  myisam_sort_buffer_size = 8M  
  character-set-server=utf8  
  init_connect='SET NAMES utf8' 
# Don't listen on a TCP/IP port at all. This can be a security enhancement,  
# if all processes that need to connect to mysqld run on the same host.  
# All interaction with mysqld must be made via Unix sockets or named pipes.  
# Note that using this option without enabling named pipes on Windows  
# (via the "enable-named-pipe" option) will render mysqld useless!  
#   
#skip-networking  

  # Replication Master Server (default)  
  # binary logging is required for replication  
  log-bin=mysql-bin  

    # binary logging format - mixed recommended  
    binlog_format=mixed  

      # required unique id between 1 and 2^32 - 1  
      # defaults to 1 if master-host is not set  
      # but will not function as a master if omitted  
      server-id   = 1  

    # Replication Slave (comment out master section to use this)  
    #  
    # To configure this host as a replication slave, you can choose between  
    # two methods :  
    #  
    # 1) Use the CHANGE MASTER TO command (fully described in our manual) -  
    #    the syntax is:  
    #  
    #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,  
    #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;  
    #  
    #    where you replace <host>, <user>, <password> by quoted strings and  
    #    <port> by the master's port number (3306 by default).  
    #  
    #    Example:  
    #  
    #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,  
    #    MASTER_USER='joe', MASTER_PASSWORD='secret';  
    #  
    # OR  
    #  
    # 2) Set the variables below. However, in case you choose this method, then  
    #    start replication for the first time (even unsuccessfully, for example  
    #    if you mistyped the password in master-password and the slave fails to  
    #    connect), the slave will create a master.info file, and any later  
    #    change in this file to the variables' values below will be ignored and  
    #    overridden by the content of the master.info file, unless you shutdown  
    #    the slave server, delete master.info and restart the slaver server.  
    #    For that reason, you may want to leave the lines below untouched  
    #    (commented) and instead use CHANGE MASTER TO (see above)  
    #  
    # required unique id between 2 and 2^32 - 1  
    # (and different from the master)  
    # defaults to 2 if master-host is set  
    # but will not function as a slave if omitted  
    #server-id       = 2  
    #  
    # The replication master for this slave - required  
    #master-host     =   <hostname>  
    #  
    # The username the slave will use for authentication when connecting  
    # to the master - required  
    #master-user     =   <username>  
    #  
    # The password the slave will authenticate with when connecting to  
    # the master - required  
    #master-password =   <password>  
    #  
    # The port the master is listening on.  
    # optional - defaults to 3306  
    #master-port     =  <port>  
    #  
    # binary logging - not required for slaves, but recommended  
    #log-bin=mysql-bin  

      # Uncomment the following if you are using InnoDB tables  
      #innodb_data_home_dir = /usr/local/mysql/data  
      #innodb_data_file_path = ibdata1:10M:autoextend  
      #innodb_log_group_home_dir = /usr/local/mysql/data  
      # You can set .._buffer_pool_size up to 50 - 80 %  
      # of RAM but beware of setting memory usage too high  
      #innodb_buffer_pool_size = 16M  
      #innodb_additional_mem_pool_size = 2M  
      # Set .._log_file_size to 25 % of buffer pool size  
      #innodb_log_file_size = 5M  
      #innodb_log_buffer_size = 8M  
      #innodb_flush_log_at_trx_commit = 1  
      #innodb_lock_wait_timeout = 50  

        [mysqldump]  
        quick  
        max_allowed_packet = 16M  

          [mysql]  
          no-auto-rehash  
          # Remove the next comment character if you are not familiar with SQL  
          #safe-updates  
          default-character-set=utf8   

        [myisamchk]  
        key_buffer_size = 20M  
        sort_buffer_size = 20M  
        read_buffer = 2M  
        write_buffer = 2M  

          [mysqlhotcopy]  
          interactive-timeout

在这之后,你需要把出现在主用户目录下的my.cnf移到mysql目录下 ,实现正常命令执行

出现欢迎界面,大功告成

此后输入mysql -u root -p 不再会报command not found

希望大家数据库课设做的愉快

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 您可以在命令中使用"taskkill /f /im *进程名*" 命令来停止目标进程,"*进程名*" 替换成您想要停止的进程名。如果您想要停止所有进程,可以使用"taskkill /f /im *" 命令。但是,请注意,停止某些系统关键进程可能会导致系统不稳定,因此请谨慎操作。 ### 回答2: 要使用命令停止当前进的所有进程,可以按照以下几个步骤进操作: 1. 打开命令终端窗口。在Windows系统中,可以使用快捷键"Win + R"打开"运"对话框,然后输入"cmd"并按下回车键。在Mac OS和Linux系统中,可以通过在"应用程序"菜单中找到"终端"或通过快捷键"Ctrl + Alt + T"打开终端。 2. 输入命令"tasklist"(Windows系统)或"ps -ef"(Mac OS和Linux系统)查看当前正在运的进程列表。 3. 根据进程列表,找到要停止的进程的PID(进程标识符)。在Windows系统中,PID位于"PID"列。在Mac OS和Linux系统中,PID位于"PID"或"PID/PPID"列。 4. 输入命令"taskkill /F /PID <PID>"(Windows系统)或"kill <PID>"(Mac OS和Linux系统)停止指定的进程。其中,<PID>应替换为要停止的进程的PID。 5. 重复步骤4,直到停止所有要结束的进程。可以使用循环结构来自动化这个过程。 总结起来,要使用命令停止当前进的所有进程,需要打开命令终端窗口,查看进程列表并获得要停止的进程的PID,然后使用适当的命令停止这些进程。 ### 回答3: 要通过命令停止当前正在运的所有进程,可以按照以下步骤进: 1. 打开命令终端:在Windows系统中,可以按下Win键 + R键,然后输入"cmd"并按下回车键;在Linux或Mac系统中,可以打开终端应用程序。 2. 查看所有正在运的进程:在命令中键入命令"tasklist"(Windows系统)或"ps"(Linux或Mac系统),然后按下回车键。这将显示所有当前正在运的进程的列表,包括进程ID(PID)和名称。 3. 停止进程:在命令中键入命令"taskkill /F /PID <PID>"(Windows系统)或"kill <PID>"(Linux或Mac系统),其中"<PID>"是要停止的进程的PID。可以一次停止一个或多个进程,只需在命令中提供所有需要停止的进程的PID。 4. 确认进程被停止:再次执步骤2中的命令,确保要停止的进程已经被成功终止。 请注意,停止某些进程可能会导致不可逆的数据丢失或系统崩溃。在执此操作之前,请确保已保存并关闭所有需要保存的文件和应用程序。另外,停止某些系统关键进程可能会导致系统不稳定,请谨慎操作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值