macOS安装和配置MySQL5.7
官方推荐的安装方法请看:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
下载最新的mysql tar.gz 包,把解压缩后的包移动到 /usr/local 目录下,
sudo mv mysql-5.7.15-osx10.11-x86_64 /usr/local/mysql
修改目录的权限
sudo chown -R xinxingegeya:wheel mysql
初始化mysql,
➜ 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!
更改临时密码,
➜ 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.
测试重启,
➜ support-files ./mysql.server restart
Shutting down MySQL
. SUCCESS!
Starting MySQL
. SUCCESS!
测试关闭
➜ support-files ./mysql.server stop
Shutting down MySQL
. SUCCESS!
测试登录
➜ ~ 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======