溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MAC下安裝MySQL 8.0.16教訓記錄

發布時間:2020-07-02 18:25:31 來源:網絡 閱讀:5181 作者:googlingman 欄目:MySQL數據庫

問題

花了兩天多時間才算解決問題!原來也在幾個環境下使用過MySQL,而且也熟悉另外幾個關系數據庫,原以為也就是安裝時間上花費一點。但是,現在總結來看,對于MAC下知識了解還是太少,導致走了不少彎路?,F記錄于此,有興趣的朋友參考一下。

我使用的是從Oracle官方網站上下載目前最新的mysql-8.0.16-macos10.14-x86_64.dmg安裝方式。一開始的安裝過程沒有問題,與其他.dmg文件的安裝方式大同小異。

但是,安裝結束后,在MAC終端上運行如下命令出錯:

mysql -uroot -p

或者只運行mysql命令,都導致如下錯誤:

MAC下安裝MySQL 8.0.16教訓記錄

這個錯誤可謂經典,在很多類UNIX平臺上對于不同版本的MYSQL安裝與初步使用中都出現過這個提示!

我在這個錯誤上也糾結了相當長的時間!

求解過程

在幾經嘗試均失敗后,我注意到有網文提到分析錯誤跟蹤日志的辦法。于是,我也耐著性子跟蹤分析錯誤日志文件mysqld.local.err。
注意,MYSQL 8.0的安全性(與在MAC平臺上安裝很有關系)越來越高,想分析一下其相應路徑下的內容需要不斷地修改權限才行。最終,觀察此文件中發現有反復出現的如下提示信息:

[System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) starting as process 1036
2019-05-09T00:52:09.981310Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-05-09T00:52:09.982012Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2019-05-09T00:52:10.356462Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-05-09T00:52:10.356884Z 0 [ERROR] [MY-010273] [Server] Could not create unix socket lock file /tmp/mysql.sock.lock.
2019-05-09T00:52:10.356892Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
2019-05-09T00:52:10.357090Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-05-09T00:52:11.822090Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.16) MySQL Community Server - GPL.

再結合“系統偏好設置”中MYSQL圖標打開時注意到的,發現MYSQL每隔幾秒鐘就連接與斷開現象,與這里的日志記錄一致了。

接下來,使用上面錯誤中提到的關鍵詞“Could not create unix socket lock file /tmp/mysql.sock.lock”搜索......

因為網文中有些同學雖然解決了問題,但是由于版本不同,而且有些理解也不是很到位,導致我也跟著瞎走了不少路。

最終得到的解答是,上面錯誤原因在于沒有對于/tmp目錄的寫權限所致。

于是,運行如下命令:

sudo chown -R mysql:mysql /tmp/

再次在命令行運行如下命令成功啟動mysql——通過上面的“系統偏好設置”中MYSQL圖標對應的面板也能觀察到。

sudo mysqld_safe

有關mysqld_safe命令文件的作用在此不贅述,請自行搜索解答。

注意:上面在初步通過向導安裝完MYSQL后,現在版本中并不會自動創建配置文件my.cnf,需要自己創建,其典型的位置是
/etc路徑下。這個文件的內容也是我從網上搜索到的,請參考,現列舉于下:

[client]
  default-character-set=utf8

#password   =root 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>
        [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

注意:上面配置文件中,在我們的興趣范圍的最關鍵的一行是:

socket = /tmp/mysql.sock

有關文件mysql.sock,你會在網站上搜索出很多,在此也不贅述。

總之,經過上面的操作,我們擁有了對于/tmp路徑的操作權后,在正常啟動mysql后,就會生成這個文件(這個文件不是事先就存在的?。。。?。

另外,網文中還提到如下描述:

在配置my.cnf文件的時候,一開始我是使用Mac自帶的文本編輯軟件創建my.cnf文件,但是文件的編碼格式是utf-8的,在MySQL讀取的時候會報錯,之后查找相關資料發現MySQL的配置文件需要時ASNI/ASCII格式的,所以我直接在終端中用vim命令直接創建了my.cnf文件,然后將配置寫入,就可以了。
首先打開終端,cd 到 /etc路徑下,然后使用命令

sudo cp ~/Desktop/my.cnf ./     (我是將my.cnf文件放在了桌面上)

將該文件拷貝到/etc路徑下,然后修改文件權限

sudo chmod 664 my.cnf    

一定要修改為664,不然MySQL讀取文件的時候權限會出錯

說得很細致,很好。也就是說,我們應當使用命令行下的vi命令創建這個配置文件并確保其使用的是ASCII格式。默認地,使用vi創建的文件自然是純文本格式的,符合要求。另外,你也可以很容易地使用file命令來查看一個文件的格式。

問題到此,解決了60%吧,或者說80%。至此,配置文件創建了,mysql服務能夠正常啟動了。

但是,運行如下命令還是出錯:

mysql -uroot -p

錯誤如下:

ERROR 1045 (28000): Access denied for user 'root'@'localhost'``

在解決上述問題過程中,貢獻最大的是文章https://www.cnblogs.com/hamsterPP/p/5274052.html 重要參考。

但是,在最后修改root用戶密碼時所用腳本命令過時了,不再使用UPDATE命令,而改為使用ALTER命令。對此,官網上也有明確說明。

命令如下:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

但是,在運行上述命令前一定要運行下面的刷新命令:

flush privileges;

注意,在上面重要參考文章中提到,在重置(創建)root密碼過程中,需要開兩個控制臺窗口,切記!

最后一句心得:紙上得來終覺淺,絕知此事要躬行!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女