Mac OS安装mysql教程

https://blog.csdn.net/u010066934/article/details/78459403

前两天为了开发方便,在自己电脑上装了一个mysql,发现Mac上的安装步骤中还是有些注意事项的,于是整理了这篇博客。

1、下载

进入官网www.mysql.com下载所需的mysql版本和安装包格式。 
注:Mac需下载dmg格式文件。

这里写图片描述

下载完毕后,点击pkg安装包,next进行安装。

2、安装

安装完毕后,进入系统偏好设置,找到mysql。 
这里写图片描述

点击Start Mysql Server,显示启动成功。

Tips: 
(1)mysql默认安装路径是:/usr/local/mysql 
(2)此时需要记录下临时密码,如w?8gUt-xfp_s。

3、配置

3.1修改临时密码

数据库连接工具无法使用临时密码进行连接,会报错密码失效。

登录mysql的默认路径的bin下,使用如下命令,进行修改。其中,123456为你的新密码。

这里写图片描述
 

3.2修改字符集

一般,my-default.cnf文件在mysql/support-files下。若存在,将其拷贝到/etc下,并修改名称为my.cnf。若没有,则手动建立该文件于/etc下。

新建文件命令: 
sudo vim my.cnf

设置文件权限: 
chmod 775 my.cnf

添加文件内容: 
将如下配置内容写入到文件中

<span style="color:#000000"><code># Example MySQL config <span style="color:#000088">file</span> <span style="color:#000088">for</span> medium systems.  
  #  
  # This <span style="color:#000088">is</span> <span style="color:#000088">for</span> a system <span style="color:#000088">with</span> little memory (<span style="color:#006666">32</span>M - <span style="color:#006666">64</span>M) where MySQL plays  
  # an important part, <span style="color:#000088">or</span> systems up <span style="color:#000088">to</span> <span style="color:#006666">128</span>M where MySQL <span style="color:#000088">is</span> used together <span style="color:#000088">with</span>  
  # other programs (such as a web server)  
  #  
  # MySQL programs look <span style="color:#000088">for</span> option files <span style="color:#000088">in</span> a set <span style="color:#000088">of</span>  
  # locations which depend <span style="color:#000088">on</span> the deployment platform.  
  # You can copy this option <span style="color:#000088">file</span> <span style="color:#000088">to</span> one <span style="color:#000088">of</span> those  
  # locations. <span style="color:#000088">For</span> information about these locations, see:  
  # http://dev.mysql.com/doc/mysql/en/option-files.html  
  #  
  # <span style="color:#000088">In</span> this <span style="color:#000088">file</span>, you can <span style="color:#000088">use</span> <span style="color:#000088">all</span> long options that a program supports.  
  # <span style="color:#000088">If</span> you want <span style="color:#000088">to</span> know which options a program supports, run the program  
  # <span style="color:#000088">with</span> the <span style="color:#009900">"--help"</span> option.  
  # The following options will be passed <span style="color:#000088">to</span> <span style="color:#000088">all</span> MySQL clients  
  [client]
  <span style="color:#000088">default</span>-<span style="color:#4f4f4f">character</span>-set=utf8
  #password   = your_password  
  <span style="color:#000088">port</span>        = <span style="color:#006666">3306</span>  
  socket      = /tmp/mysql.sock   
  # Here follows entries <span style="color:#000088">for</span> some specific programs  
  # The MySQL server  
  [mysqld]
  <span style="color:#4f4f4f">character</span>-set-server=utf8
  init_connect='SET  NAMES utf8'
  <span style="color:#000088">port</span>        = <span style="color:#006666">3306</span>  
  socket      = /tmp/mysql.sock  
  skip-external-locking  
  key_buffer_size = <span style="color:#006666">16</span>M  
  max_allowed_packet = <span style="color:#006666">1</span>M  
  table_open_cache = <span style="color:#006666">64</span>  
  sort_buffer_size = <span style="color:#006666">512</span>K  
  net_buffer_length = <span style="color:#006666">8</span>K  
  read_buffer_size = <span style="color:#006666">256</span>K  
  read_rnd_buffer_size = <span style="color:#006666">512</span>K  
  myisam_sort_buffer_size = <span style="color:#006666">8</span>M  
  <span style="color:#4f4f4f">character</span>-set-server=utf8  
  init_connect='SET  NAMES utf8' 
# Don't listen <span style="color:#000088">on</span> a TCP/IP <span style="color:#000088">port</span> at <span style="color:#000088">all</span>. This can be a security enhancement,  
# <span style="color:#000088">if</span> <span style="color:#000088">all</span> processes that need <span style="color:#000088">to</span> connect <span style="color:#000088">to</span> mysqld run <span style="color:#000088">on</span> the same host.  
# <span style="color:#000088">All</span> interaction <span style="color:#000088">with</span> mysqld must be made via Unix sockets <span style="color:#000088">or</span> named pipes.  
# Note that using this option without enabling named pipes <span style="color:#000088">on</span> Windows  
# (via the <span style="color:#009900">"enable-named-pipe"</span> option) will render mysqld useless!  
#   
#skip-networking  
# Replication Master Server (<span style="color:#000088">default</span>)  
  # binary logging <span style="color:#000088">is</span> required <span style="color:#000088">for</span> replication  
  log-bin=mysql-bin  
# binary logging format - mixed recommended  
    binlog_format=mixed  
# required unique id between <span style="color:#006666">1</span> <span style="color:#000088">and</span> <span style="color:#006666">2</span>^<span style="color:#006666">32</span> - <span style="color:#006666">1</span>  
      # defaults <span style="color:#000088">to</span> <span style="color:#006666">1</span> <span style="color:#000088">if</span> master-host <span style="color:#000088">is</span> <span style="color:#000088">not</span> set  
      # but will <span style="color:#000088">not</span> <span style="color:#000088">function</span> as a master <span style="color:#000088">if</span> omitted  
      server-id   = <span style="color:#006666">1</span>  
# Replication Slave (comment <span style="color:#000088">out</span> master section <span style="color:#000088">to</span> <span style="color:#000088">use</span> this)  
    #  
    # <span style="color:#000088">To</span> configure this host as a replication slave, you can choose between  
    # two methods :  
    #  
    # <span style="color:#006666">1</span>) <span style="color:#000088">Use</span> the CHANGE MASTER <span style="color:#000088">TO</span> command (fully described <span style="color:#000088">in</span> our manual) -  
    #    the syntax <span style="color:#000088">is</span>:  
    #  
    #    CHANGE MASTER <span style="color:#000088">TO</span> MASTER_HOST=<host>, MASTER_PORT=<<span style="color:#000088">port</span>>,  
    #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;  
    #  
    #    where you replace <host>, <user>, <password> by quoted strings <span style="color:#000088">and</span>  
    #    <<span style="color:#000088">port</span>> by the master's <span style="color:#000088">port</span> number (<span style="color:#006666">3306</span> by <span style="color:#000088">default</span>).  
    #  
    #    Example:  
    #  
    #    CHANGE MASTER <span style="color:#000088">TO</span> MASTER_HOST='<span style="color:#006666">125.564</span><span style="color:#006666">.12</span><span style="color:#006666">.1</span>', MASTER_PORT=<span style="color:#006666">3306</span>,  
    #    MASTER_USER='joe', MASTER_PASSWORD='secret';  
    #  
    # <span style="color:#000088">OR</span>  
    #  
    # <span style="color:#006666">2</span>) Set the variables below. However, <span style="color:#000088">in</span> <span style="color:#000088">case</span> you choose this method, <span style="color:#000088">then</span>  
    #    start replication <span style="color:#000088">for</span> the first <span style="color:#4f4f4f">time</span> (even unsuccessfully, <span style="color:#000088">for</span> example  
    #    <span style="color:#000088">if</span> you mistyped the password <span style="color:#000088">in</span> master-password <span style="color:#000088">and</span> the slave fails <span style="color:#000088">to</span>  
    #    connect), the slave will create a master.info <span style="color:#000088">file</span>, <span style="color:#000088">and</span> any later  
    #    change <span style="color:#000088">in</span> this <span style="color:#000088">file</span> <span style="color:#000088">to</span> the variables' values below will be ignored <span style="color:#000088">and</span>  
    #    overridden by the content <span style="color:#000088">of</span> the master.info <span style="color:#000088">file</span>, unless you shutdown  
    #    the slave server, delete master.info <span style="color:#000088">and</span> restart the slaver server.  
    #    <span style="color:#000088">For</span> that reason, you may want <span style="color:#000088">to</span> leave the lines below untouched  
    #    (commented) <span style="color:#000088">and</span> instead <span style="color:#000088">use</span> CHANGE MASTER <span style="color:#000088">TO</span> (see above)  
    #  
    # required unique id between <span style="color:#006666">2</span> <span style="color:#000088">and</span> <span style="color:#006666">2</span>^<span style="color:#006666">32</span> - <span style="color:#006666">1</span>  
    # (<span style="color:#000088">and</span> different from the master)  
    # defaults <span style="color:#000088">to</span> <span style="color:#006666">2</span> <span style="color:#000088">if</span> master-host <span style="color:#000088">is</span> set  
    # but will <span style="color:#000088">not</span> <span style="color:#000088">function</span> as a slave <span style="color:#000088">if</span> omitted  
    #server-id       = <span style="color:#006666">2</span>  
    #  
    # The replication master <span style="color:#000088">for</span> this slave - required  
    #master-host     =   <hostname>  
    #  
    # The username the slave will <span style="color:#000088">use</span> <span style="color:#000088">for</span> authentication <span style="color:#000088">when</span> connecting  
    # <span style="color:#000088">to</span> the master - required  
    #master-user     =   <username>  
    #  
    # The password the slave will authenticate <span style="color:#000088">with</span> <span style="color:#000088">when</span> connecting <span style="color:#000088">to</span>  
    # the master - required  
    #master-password =   <password>  
    #  
    # The <span style="color:#000088">port</span> the master <span style="color:#000088">is</span> listening <span style="color:#000088">on</span>.  
    # optional - defaults <span style="color:#000088">to</span> <span style="color:#006666">3306</span>  
    #master-<span style="color:#000088">port</span>     =  <<span style="color:#000088">port</span>>  
    #  
    # binary logging - <span style="color:#000088">not</span> required <span style="color:#000088">for</span> slaves, but recommended  
    #log-bin=mysql-bin  
# Uncomment the following <span style="color:#000088">if</span> you are using InnoDB tables  
      #innodb_data_home_dir = /usr/local/mysql/data  
      #innodb_data_file_path = ibdata1:<span style="color:#006666">10</span>M:autoextend  
      #innodb_log_group_home_dir = /usr/local/mysql/data  
      # You can set .._buffer_pool_size up <span style="color:#000088">to</span> <span style="color:#006666">50</span> - <span style="color:#006666">80</span> %  
      # <span style="color:#000088">of</span> RAM but beware <span style="color:#000088">of</span> setting memory usage too high  
      #innodb_buffer_pool_size = <span style="color:#006666">16</span>M  
      #innodb_additional_mem_pool_size = <span style="color:#006666">2</span>M  
      # Set .._log_file_size <span style="color:#000088">to</span> <span style="color:#006666">25</span> % <span style="color:#000088">of</span> <span style="color:#000088">buffer</span> pool size  
      #innodb_log_file_size = <span style="color:#006666">5</span>M  
      #innodb_log_buffer_size = <span style="color:#006666">8</span>M  
      #innodb_flush_log_at_trx_commit = <span style="color:#006666">1</span>  
      #innodb_lock_wait_timeout = <span style="color:#006666">50</span>  
[mysqldump]  
        quick  
        max_allowed_packet = <span style="color:#006666">16</span>M  
[mysql]  
          no-auto-rehash  
          # Remove the <span style="color:#000088">next</span> comment <span style="color:#4f4f4f">character</span> <span style="color:#000088">if</span> you are <span style="color:#000088">not</span> familiar <span style="color:#000088">with</span> SQL  
          #safe-updates  
          <span style="color:#000088">default</span>-<span style="color:#4f4f4f">character</span>-set=utf8   
[myisamchk]  
        key_buffer_size = <span style="color:#006666">20</span>M  
        sort_buffer_size = <span style="color:#006666">20</span>M  
        read_buffer = <span style="color:#006666">2</span>M  
        write_buffer = <span style="color:#006666">2</span>M  
[mysqlhotcopy]  
          interactive-timeout
</code></span>

重启后登录mysql client ,输入show variables like ‘%char%’;进行查看。

4、小结

选择稳定的且适合你系统的安装包; 
权限问题实在搞不定记得sudo; 
vi操作文件要小心。

以上,世上无难事,只怕有心人。

猜你喜欢

转载自blog.csdn.net/dufufd/article/details/82728277