macOS安裝和配置MySQL5.7html
官方推薦的安裝方法請看:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.htmlmysql
下載最新的mysql tar.gz 包,把解壓縮後的包移動到 /usr/local 目錄下,sql
sudo mv mysql-5.7.15-osx10.11-x86_64 /usr/local/mysql
修改目錄的權限測試
sudo chown -R xinxingegeya:wheel mysql
初始化mysql,this
➜ mysql bin/mysqld --initialize --user=xinxingegeya --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2016-09-25T06:41:00.870572Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-09-25T06:41:00.880225Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive 2016-09-25T06:41:01.034242Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-09-25T06:41:01.060623Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-09-25T06:41:01.124713Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0604438e-82eb-11e6-ac32-baec7272e731. 2016-09-25T06:41:01.140844Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2016-09-25T06:41:01.144552Z 1 [Note] A temporary password is generated for root@localhost: VhQr7aha4h.X
啓動mysql,編碼
➜ support-files ./mysql.server start Starting MySQL . SUCCESS!
更改臨時密碼,rest
➜ mysql bin/mysqladmin -u root -p password 034039 Enter password: mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
測試重啓,code
➜ support-files ./mysql.server restart Shutting down MySQL . SUCCESS! Starting MySQL . SUCCESS!
測試關閉server
➜ support-files ./mysql.server stop Shutting down MySQL . SUCCESS!
測試登陸htm
➜ ~ mysql -u root -p034039 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 2 Server version: 5.7.15 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
查看mysql編碼,
mysql> show variables like '%char%' ; +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql/share/charsets/ | +--------------------------+----------------------------------+ 8 rows in set (0.01 sec)
修改mysql編碼 macOS上安裝 MySQL 默認是沒有 my.cnf 配置文件的,MySQL 使用默認配置運行。若是須要對 MySQL 進行定製,複製「/usr/local/mysql/support-files/」目錄下的一個 cnf 文件到「/etc/」目錄下並重命名爲 my.cnf,添加以下配置,
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] character-set-server=utf8
重啓mysql,查看編碼方式,
mysql> show variables like '%char%' ; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 2 Current database: *** NONE *** +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql/share/charsets/ | +--------------------------+----------------------------------+ 8 rows in set (0.01 sec) mysql>
======END======