官方: download: https://dev.mysql.com/downloads/mysql/ mysql參考文檔:https://dev.mysql.com/doc/ 環境: macOS Mojave 10.14.2 用戶: 管理員用戶,期間沒有新建mysql用戶或組 安裝包: mysq ...
官方:
- download: https://dev.mysql.com/downloads/mysql/
- mysql參考文檔:https://dev.mysql.com/doc/
環境:
- macOS Mojave 10.14.2
用戶:
- 管理員用戶,期間沒有新建mysql用戶或組
安裝包:
- mysql-8.0.13-macos10.14-x86_64.tar.gz
安裝配置
1.解壓
下載的tar.gz解壓後,並移動到/usr/local/mysql,目錄結構如下:
$ pwd
/usr/local
$ tree mysql -L 1
mysql
├── LICENSE
├── LICENSE.router
├── README
├── README.router
├── bin
├── data
├── docs
├── include
├── lib
├── man
├── run
├── share
└── support-files
實際上是按照Unix目錄結構的規範,建議這麼做。
本人實際操作過程中,只是通過sudo ln -s ${MYSQL_HOME} /usr/local/mysql
,創建了一個軟鏈接。
解壓命令:tar -xzvf ${filename}
2.修改許可權:sudo chown -R usr:group /usr/local/mysql
3.初始化
$ cd /usr/local/mysql
$ bin/mysqld --initialize --user=ephemerid --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-01-20T05:50:19.601053Z 0 [System] [MY-013169] [Server] /Workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 1045
2019-01-20T05:50:19.603274Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2019-01-20T05:50:21.143953Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: A_mBvrbnD0*r
2019-01-20T05:50:22.000946Z 0 [System] [MY-013170] [Server] /Workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server has completed
ephemerid是我的用戶名,改成自己的。
後面兩個選項的含義,見後文MY-011011。
前面提到過,本人使用了軟鏈接,所以控制台信息中看到的mysql實際的目錄。
註意這個“A temporary password is generated for root@localhost”
5.啟動
$ support-files/mysql.server start
Starting MySQL
. SUCCESS!
6.連接及修改初始密碼
$ bin/mysql -uroot -pA_mBvrbnD0*r
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'pass123456';
Query OK, 0 rows affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> exit
Bye
!!!平常輸入密碼的時候不要直接添加在-p
選項後面了,會被看到的,一定要註意安全!!!
第一次登陸時,會提示需要重置密碼:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'pass123456';
7.停止服務
$ support-files/mysql.server stop
Shutting down MySQL
.. SUCCESS!
EORROR
The server quit without updating PID file
在未初始化,就啟動時出現了:
$ sudo ./support-files/mysql.server start
Password:
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/mysql/data/ephemerid.local.pid).
解決
初始化一下,即上文提到的mysqld --initialize
MY-011011
在初始化時,沒有找到有效的mysql目錄以及mysql data目錄。
$ sudo ./bin/mysqld --initaialize --user=ephemerid
2019-01-20T05:13:45.476844Z 0 [System] [MY-010116] [Server] /Workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld (mysqld 8.0.13) starting as process 993
2019-01-20T05:13:45.480320Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /Workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/data/ is case insensitive
2019-01-20T05:13:45.487935Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-01-20T05:13:45.488090Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-01-20T05:13:45.488119Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-01-20T05:13:45.488808Z 0 [System] [MY-010910] [Server] /Workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL.
解決
就是添加的兩個選項,即上文提到的--basedir
和--datadir
瞭解更多,參考:
- https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html
以上。