http://yjph83.iteye.com/blog/2205063 (mysql5.x 在windows下安装)
1、从官网下载MySQL5.7.21解压版64位
2、解压(我的解压路径为:H:\mysql-5.7.21-winx64,我将其改名去掉-,并移动到此位置H:\develop\mysql5.7.21。
3、添加环境变量(系统变量):
变量名:MYSQL_HOME
变量值:H:\develop\mysql5.7.21
修改系统变量path,在path原有值后添加路径:%MYSQL_HOME%\bin。
以管理员身份运行命令行工具:
H:\>mysqld --version
mysqld Ver 5.7.21 for Win64 on x86_64 (MySQL Community Server (GPL))
4、在H:\develop\mysql5.7.21路径下新建配置文件:my.ini,在my.ini中保存以下内容:
[mysqld]
#### database configure
basedir=H:\develop\mysql5.7.21
datadir=H:\develop\mysql5.7.21\data\
user=mysql
symbolic-links=0
#### skip configuration
# skip-name-resolve
#### innodb_configuration
innodb_file_per_table=1
innodb_open_files=4096
innodb_buffer_pool_size=1024M
innodb_log_group_home_dir=H:\develop\mysql5.7.21\mysqllog
#### character set
character-set-server=utf8
collation-server=utf8_general_ci
lower-case-table-names=1
#### log configure
pid-file=H:\develop\mysql5.7.21\mysqllog\mysqld.pid
log-error=H:\develop\mysql5.7.21\mysqllog\mysql01.err
log-bin=H:\develop\mysql5.7.21\mysqllog\mysql01-bin
slow-query-log=1
long-query-time=2
slow-query-log-file=H:\develop\mysql5.7.21\mysqllog\mysql01-slow.log
socket=H:\develop\mysql5.7.21\mysqllog\mysql.sock
relay-log=H:\develop\mysql5.7.21\mysqllog\mysql01-relay-bin
#### replication configure
server-id = 1
replicate-wild-ignore-table = mysql.%
replicate-wild-ignore-table = information_schema.%
replicate-wild-ignore-table = performance_schema.%
replicate-wild-ignore-table = sys.%
binlog-format=ROW
binlog-row-image=full
binlog-rows-query-log-events=1
sync_binlog=1
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
#### time configure
explicit_defaults_for_timestamp=true
# [client]
#socket=H:\develop\mysql5.7.21\mysqllog\mysql.sock
5、命令行运行
H:\>mysqld --initialize --basedir=H:\develop\mysql5.7.21 --datadir=H:\develop\mysql5.7.21\data
H:\>mysqld --install
Service successfully installed.
H:\>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
6、在H:\develop\mysql5.7.21\mysqllog\mysql01.err 日志中找到
2018-06-15T01:57:06.631815Z 1 [Note] A temporary password is generated for root@localhost: Ha)w-V0&P5ta
初始密码
7、登录mysql
H:\>mysql -u root -p"Ha)w-V0&P5ta"
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.21-log
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> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password8');
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
mysql> exit;
Bye
再用新密码登录并显示数据库;
H:\>mysql -u root -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21-log MySQL Community Server (GPL)
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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
create database workbook default character set utf8 collate utf8_general_ci;
create database workbook default character set utf8mb4 collate utf8mb4_general_ci;
#以上命令是创建数据库 workbook ,设置字符集和排序;
create user workbook@'%' identified by 'password8';
#创建用户 workbook@'%', 因mysql是 用户名+主机名 才是完整的用户名;
grant all privileges on workbook.* to workbook@'%';
#给用户workbook@'%' 赋所有权限
grant select on workreport.* to workbook@'%';
#给用户workbook@'%' 读取权限
grant replication client on *.* to workbook@'%';
#给用户workbook@'%' 赋主从复制权限
flush privileges;