mac(m1)配置my.cnf

  金牌会员 | 2022-8-27 22:45:50 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 871|帖子 871|积分 2613

今天开始学习了数据库,在安装MySQL之后启动一直报错,然后在网上找了很多解决方法,最后用以下方法解决
对于习惯了windows的小伙伴来说,直接去安装目录里边修改my.ini就可以,对于习惯了Linux的小伙伴来说,直接修改mysql默认的/etc/my.cnf配置文件就可以,可是Mac端MySQL是默认没有配置文件的,需要自己手动创建。
1.新建etc文件

一般要在 先在/usr/local下新建一个etc 文件,注意etc为配置文件需要以管理员的身份新建进入/usr/local目录下中,然后输入以下命令
  1. sudo mkdir etc
复制代码
然后回车即可创建etc文件
2.新建my.cnf文件

然后进入etc目录下,输入以下命令
  1. sudo vi my.cnf
复制代码
然后将以下代码全部复制进去即可
  1. # Example MySQL config file for medium systems.  
  2.   #  
  3.   # This is for a system with little memory (32M - 64M) where MySQL plays  
  4.   # an important part, or systems up to 128M where MySQL is used together with  
  5.   # other programs (such as a web server)  
  6.   #  
  7.   # MySQL programs look for option files in a set of  
  8.   # locations which depend on the deployment platform.  
  9.   # You can copy this option file to one of those  
  10.   # locations. For information about these locations, see:  
  11.   # http://dev.mysql.com/doc/mysql/en/option-files.html  
  12.   #  
  13.   # In this file, you can use all long options that a program supports.  
  14.   # If you want to know which options a program supports, run the program  
  15.   # with the "--help" option.  
  16.   # The following options will be passed to all MySQL clients  
  17.   [client]
  18.   default-character-set=utf8
  19.   #password   = your_password  
  20.   port        = 3306  
  21.   socket      = /tmp/mysql.sock   
  22.   # Here follows entries for some specific programs  
  23.   # The MySQL server  
  24.   [mysqld]
  25.   character-set-server=utf8  
  26.   init_connect='SET NAMES utf8'
  27.   port        = 3306  
  28.   socket      = /tmp/mysql.sock  
  29.   skip-external-locking  
  30.   key_buffer_size = 16M  
  31.   max_allowed_packet = 1M  
  32.   table_open_cache = 64  
  33.   sort_buffer_size = 512K  
  34.   net_buffer_length = 8K  
  35.   read_buffer_size = 256K  
  36.   read_rnd_buffer_size = 512K  
  37.   myisam_sort_buffer_size = 8M  
  38. # Don't listen on a TCP/IP port at all. This can be a security enhancement,  
  39. # if all processes that need to connect to mysqld run on the same host.  
  40. # All interaction with mysqld must be made via Unix sockets or named pipes.  
  41. # Note that using this option without enabling named pipes on Windows  
  42. # (via the "enable-named-pipe" option) will render mysqld useless!  
  43. #   
  44. #skip-networking  
  45.   # Replication Master Server (default)  
  46.   # binary logging is required for replication  
  47.   log-bin=mysql-bin  
  48.     # binary logging format - mixed recommended  
  49.     binlog_format=mixed  
  50.       # required unique id between 1 and 2^32 - 1  
  51.       # defaults to 1 if master-host is not set  
  52.       # but will not function as a master if omitted  
  53.       server-id   = 1  
  54.     # Replication Slave (comment out master section to use this)  
  55.     #  
  56.     # To configure this host as a replication slave, you can choose between  
  57.     # two methods :  
  58.     #  
  59.     # 1) Use the CHANGE MASTER TO command (fully described in our manual) -  
  60.     #    the syntax is:  
  61.     #  
  62.     #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,  
  63.     #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;  
  64.     #  
  65.     #    where you replace <host>, <user>, <password> by quoted strings and  
  66.     #    <port> by the master's port number (3306 by default).  
  67.     #  
  68.     #    Example:  
  69.     #  
  70.     #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,  
  71.     #    MASTER_USER='joe', MASTER_PASSWORD='secret';  
  72.     #  
  73.     # OR  
  74.     #  
  75.     # 2) Set the variables below. However, in case you choose this method, then  
  76.     #    start replication for the first time (even unsuccessfully, for example  
  77.     #    if you mistyped the password in master-password and the slave fails to  
  78.     #    connect), the slave will create a master.info file, and any later  
  79.     #    change in this file to the variables' values below will be ignored and  
  80.     #    overridden by the content of the master.info file, unless you shutdown  
  81.     #    the slave server, delete master.info and restart the slaver server.  
  82.     #    For that reason, you may want to leave the lines below untouched  
  83.     #    (commented) and instead use CHANGE MASTER TO (see above)  
  84.     #  
  85.     # required unique id between 2 and 2^32 - 1  
  86.     # (and different from the master)  
  87.     # defaults to 2 if master-host is set  
  88.     # but will not function as a slave if omitted  
  89.     #server-id       = 2  
  90.     #  
  91.     # The replication master for this slave - required  
  92.     #master-host     =   <hostname>  
  93.     #  
  94.     # The username the slave will use for authentication when connecting  
  95.     # to the master - required  
  96.     #master-user     =   <username>  
  97.     #  
  98.     # The password the slave will authenticate with when connecting to  
  99.     # the master - required  
  100.     #master-password =   <password>  
  101.     #  
  102.     # The port the master is listening on.  
  103.     # optional - defaults to 3306  
  104.     #master-port     =  <port>  
  105.     #  
  106.     # binary logging - not required for slaves, but recommended  
  107.     #log-bin=mysql-bin  
  108.       # Uncomment the following if you are using InnoDB tables  
  109.       #innodb_data_home_dir = /usr/local/mysql/data  
  110.       #innodb_data_file_path = ibdata1:10M:autoextend  
  111.       #innodb_log_group_home_dir = /usr/local/mysql/data  
  112.       # You can set .._buffer_pool_size up to 50 - 80 %  
  113.       # of RAM but beware of setting memory usage too high  
  114.       #innodb_buffer_pool_size = 16M  
  115.       #innodb_additional_mem_pool_size = 2M  
  116.       # Set .._log_file_size to 25 % of buffer pool size  
  117.       #innodb_log_file_size = 5M  
  118.       #innodb_log_buffer_size = 8M  
  119.       #innodb_flush_log_at_trx_commit = 1  
  120.       #innodb_lock_wait_timeout = 50  
  121.         [mysqldump]  
  122.         quick  
  123.         max_allowed_packet = 16M  
  124.           [mysql]  
  125.           no-auto-rehash  
  126.           # Remove the next comment character if you are not familiar with SQL  
  127.           #safe-updates  
  128.           default-character-set=utf8   
  129.         [myisamchk]  
  130.         key_buffer_size = 20M  
  131.         sort_buffer_size = 20M  
  132.         read_buffer = 2M  
  133.         write_buffer = 2M  
  134.           [mysqlhotcopy]  
  135.           interactive-timeout
  136. ————————————————
复制代码
然后按esc并输入:wq保存即可
3.设置my.cnf文件的权限

执行下面代码,否则mysql并不会读取my.cnf这个配置文件,执行下面一行命令前查看自己当前的目录,我当前是在etc目录里面的
  1. sudo chmod 664 my.cnf
复制代码
最后输入以下命令 即可启动MySQL
  1. sudo /usr/local/mysql/support-files/mysql.server start
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表