当前位置:   article > 正文

M1 Mac安装MySQL教程;my.cnf文件配置;环境变量配置;完全卸载MySQL教程,亲测有效_mac dmg 安装mysql的配置文件

mac dmg 安装mysql的配置文件

一:下载MySQL(我的系统版本为:macOS 13.2.1)

下载地址:MySQL :: Download MySQL Community Server

(1)下载所需版本的dmg安装包,点击Archives可以选择历史版本:

619e792d15d54bb7bcc7df04dbb92c1c.jpeg

 (2)这里我选择安装8.0.31。注意:版本8.x.x中所有版本可以在安装过程中设置MySQL的密码,而之前的所有版本(比如5.7.X之类的),系统会在安装过程中弹出一个弹窗,自动生成一个临时密码(一定要记住,截图)

版本8.0.31,蓝色框会显示适配系统,下载第一个.dmg文件即可

b6b96a241c984504a3bccb34cb421b97.jpeg

 下载完成后,双击打开.dmg文件:

da38d147aace47ccb0c9e4b62ecfd167.png

 再次双击安装包,即可安装:

d5fed339048140f685c748943b868c43.png

安装过程会有弹窗提示无法打开,进入系统设置,选择隐私与安全性,在最下面,选择仍要打开:

63f471fc76ef47afbd12b5d88ee68490.jpeg

5652fe241b4a4673800f63ef3a703117.png

 (安装MySQL 5.7版本过程中的临时密码弹窗图)

(3)在后续安装过程中,不要更改默认安装路径,建议选择下面这个Use Legacy Password Encryption,如果选择上面那个,后续项目在VS Code或PyCharm中连接不成功,所以这里选择下面的:

981f257aceaa490cab6b064809000a6e.jpeg

 之后设置密码,需要至少8位:

97953a0bee89407695b3c7e231a3eab7.jpeg

至此,MySQL 8.0.31安装完成,接下来是环境变量的配置。 

二:环境变量配置

(1)打开终端,输入以下命令:

  1. cd ~
  2. vim ./.bash_profile

i键,进入INSERT模式,输入以下两行代码:

  1. export PATH=$PATH:/usr/local/mysql/bin
  2. export PATH=$PATH:/usr/local/mysql/support-files

如图:

b86a8abb95cd446fa2e80843f0e5d143.png

40315dd8b20c4d48845edd558a2cb5fe.jpeg

 最后按esc,输入:wq!(注意有冒号“:”)按回车键退出。

(2)终端登录测试:

打开终端,输入:

mysql -u root -p

如果返回:

67590167016548c7a610524e1f790838.png

 则在终端重新输入:

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

注意:该方法只是临时有效,下次输入mysql -u root -p后,还是会提示:zsh:command not found:mysql,只需再次输入alias mysql=/usr/local/mysql/bin/mysql即可。

三:配置my.cnf文件

(1)在Windows下的Mysql中,安装目录修改my.ini文件就会对默认字符集进行配置,而在Mac下,默认没有配置文件,需要自己手动创建my.cnf文件来配置。在终端输入:

sudo vim /etc/my.cnf

系统提示输入电脑密码,之后进入输入模式,按i键,输入以下内容(不需要做任何修改):

  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!(注意有冒号“:”)按回车键退出。

(2)最后在终端输入以下代码,否则mysql并不会读取上面的配置文件

sudo chmod 664 /etc/my.cnf

(3)重启mysql:

alias mysql=/usr/local/mysql/bin/mysql
mysql -u root -p

f642856456f4427f808a04b193e8b90c.png

(4)进入mysql后,查看是否成功配置:

show variables like "character%";

 a75563ad04a140bd9265d5081b39c07d.png

出现以上页面,大功告成!

(5)最后退出mysql:

exit

 476419dff53141de9b7051beac5496dd.png

至此,Mac中MySQL的my.cnf文件配置成功! 

四:(M1)Mac彻底卸载MySQL

(1)终端输入:

cd ~

打开/usr文件

open /usr

(2)桌面会弹出/usr文件夹的窗口,进入到local文件夹,在该目录下进入终端,然后依次输入以下命令:

  1. sudo rm /usr/local/mysql
  2. sudo rm -rf /usr/local/mysql*
  3. sudo rm -rf /Library/StartupItems/MySQLCOM
  4. sudo rm -rf /Library/PreferencePanes/My*
  5. rm -rf ~/Library/PreferencePanes/My*
  6. sudo rm -rf /Library/Receipts/mysql*
  7. sudo rm -rf /Library/Receipts/MySQL*
  8. sudo rm -rf /var/db/receipts/com.mysql.*

有些内容可能会提示没有找到,不用管。

(3)卸载完成后,进入系统设置,最下方的MySQL标志消失,代表卸载成功!

a57d000746954e86adee1ddd7269bea6.png

该标志消失,代表卸载成功! 

(4)在安装MySQL后没有更改默认安装路径,通过上述卸载方法,就可以将MySQL完全卸载。

如果更改过默认安装路径,那么除了执行上面的命令之外,检查以下文件中是否含有对应的文件,有的话删除即可。

检查 /usr/local/Cellar 目录是否有mysql文件,有的话删除。
检查 /usr/local/var 里的mysql文件,有的话删除。
检查 /tmp 里的 mysql.sock、mysql.sock.lock、my.cnf 文件,有的话删除。
err文件以及pid文件都是在 /usr/local/var/mysql 中,有的话删除。
brew安装的安装包存储在 /usr/local/Library/Cache/Homebrew ,有的话删除。
最后,在终端执行:

brew cleanup

(5)至此,本篇分享教程结束,欢迎关注!

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号