mac(m1)配置my.cnf

今天开始学习了数据库,在安装MySQL之后启动一直报错,然后在网上找了很多解决方法,最后用以下方法解决

对于习惯了windows的小伙伴来说,直接去安装目录里边修改my.ini就可以,对于习惯了Linux的小伙伴来说,直接修改mysql默认的/etc/my.cnf配置文件就可以,可是Mac端MySQL是默认没有配置文件的,需要自己手动创建。

1.新建etc文件

一般要在 先在/usr/local下新建一个etc 文件,注意etc为配置文件需要以管理员的身份新建 进入/usr/local目录下中,然后输入以下命令

sudo mkdir etc

然后回车即可创建etc文件

2.新建my.cnf文件

然后进入etc目录下,输入以下命令

sudo vi my.cnf

然后将以下代码全部复制进去即可

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
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
&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;

</port></password></username></hostname></port></password></user></host></password></user></port></host>

然后按esc并输入:wq保存即可

3.设置my.cnf文件的权限

执行下面代码,否则mysql并不会读取my.cnf这个配置文件,执行下面一行命令前查看自己当前的目录,我当前是在etc目录里面的

mac(m1)配置my.cnf
sudo chmod 664 my.cnf

最后输入以下命令 即可启动MySQL

sudo /usr/local/mysql/support-files/mysql.server start

Original: https://www.cnblogs.com/twq46/p/16484537.html
Author: 剑断青丝ii
Title: mac(m1)配置my.cnf

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/609725/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 开篇说几句

    一直一览都是博客园的粉丝,从中查询了很多资料,给了我很多的帮助,随着时间的积累,自己有一些感悟和学习笔记,今天申请了个博客吧,吧自己的一些想法写出来,保留份记忆。 Original…

    Java 2023年6月8日
    079
  • linux安装nacos2.x集群

    新建并编辑nacos.service文件,并复制/转移到/etc/systemd/system/nacos.service中,**代表你的安装目录,可根据实际情况进行更改添加内容如…

    Java 2023年6月16日
    060
  • 尚医通项目总结(二)———-Mybatis与Mybatis Plus

    Mybatis是持久层解决方案,它是一个半自动化的ORM框架,底层封装了JDBC,可以简化对数据库的增删改查操作。Mybatis的半自动体现在,在查询关联对象或者关联集合对象时,需…

    Java 2023年6月5日
    0108
  • CSharp:Observer Pattern

    csharp;gutter:true; /// /// Summary description for Observer.</p> <pre><cod…

    Java 2023年6月16日
    081
  • WordPress网站中添加百度统计代码

    百度统计是流量分析平台,帮助收集网站访问数据,提供流量趋势、来源分析、转化跟踪、页面热力图、访问流等多种统计分析服务,同时与百度搜索、百度推广、云服务无缝结合,为网站的精细化运营决…

    Java 2023年6月8日
    086
  • nginx用户认证配置( Basic HTTP authentication)

    ngx_http_auth_basic_module模块实现让访问着,只有输入正确的用户密码才允许访问web内容。web上的一些内容不想被其他人知道,但是又想让部分人看到。ngin…

    Java 2023年5月30日
    082
  • java循环结构

    一. If语句的格式及其执行流程(3种) if(关系表达式) { 语句体 执行流程: 首先判断关系表达式看其结果是true还是false 如果是true就执行语句体 如果是fals…

    Java 2023年6月5日
    059
  • SpringBoot包扫描之多模块多包名扫描和同类名扫描冲突解决

    前言 我们在开发 springboot项目时候,创建好SpringBoot项目就可以通过启动类直间启动,运行一个web项目,非常方便简单,不像我们之前通过 Spring+Sprin…

    Java 2023年6月13日
    097
  • Java线程池中三种方式创建 ThreadFactory 设置线程名称

    本文讲一下Java线程池中创建 ThreadFactory 设置线程名称的三种方式。设置线程名称是很重要的,如果你没有设置过,说明你还”涩世”不深,这里面的…

    Java 2023年5月29日
    068
  • 理解、学习与使用 JAVA 中的 OPTIONAL

    转换值 有很多种方法可以转换 Optional 的值。我们从 map() 和 flatMap() 方法开始。 先来看一个使用 _map()_API 的例子: map() 对值应用(…

    Java 2023年5月29日
    065
  • ArrayList

    1、定义 ArrayList 类是一个可以动态修改的数组,与普通数组的区别就是它是没有固定大小的限制,我们可以添加或删除元素。 ArrayList 继承了 AbstractList…

    Java 2023年6月5日
    077
  • Word转换HTML(Java实用版)

    前言: 在业务中,如果需要在浏览器中预览Word文档,或者需要将Word文档转成HTML文件保存,那么本章内容,可以帮助到你。 实现这一功能,有多种实现方式,如:docx4j、po…

    Java 2023年6月8日
    069
  • 百行以内实现复杂数学表达式计算

    一改以前 本次先上代码 package good;//Evaluate complex expressionsimport java.io.IOException;import j…

    Java 2023年6月5日
    096
  • 索引有什么分类?

    索引有什么分类? – 1、主键索引:名为primary的唯一非空索引,不允许有空值。 – 2、唯一索引:索引列中的值必须是唯一的,但是允许为空值。唯一索引和…

    Java 2023年6月5日
    084
  • 分布式多级缓存(本地缓存,redis缓存)

    结构包: 使用案例: 实现效果: 1、基本并发的本地缓存,基于分布式轻量级锁的redis缓存 2、热缓存(高频访问持续缓存)+快速过期(本地缓存2秒,redis缓存10秒) 3、方…

    Java 2023年6月6日
    086
  • MySQL的安装和卸载

    MySQL的安装和卸载 一、卸载 1.停止MySQL服务:我的电脑–》管理–》服务–》MySQL服务名–》停止! 2.卸载MySQL…

    Java 2023年6月5日
    088
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球