参考:https://www.jb51.net/article/139219.htm
D:\Software\mysql-8.0.11-winx64\bin>mysqld --initialize --console
2018-06-14T02:15:42.040910Z 0 [System] [MY-013169] [Server] D:\Software\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 9196
2018-06-14T02:15:55.997459Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;sHD)Yjrd9kr
2018-06-14T02:16:03.993614Z 0 [System] [MY-013170] [Server] D:\Software\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
D:\Software\mysql-8.0.11-winx64\bin>mysqld --install
Service successfully installed.
D:\Software\mysql-8.0.11-winx64\bin>net start mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。
D:\Software\mysql-8.0.11-winx64\bin>mysql -uroot -p;sHD)Yjrd9kr
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.11
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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.05 sec)
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+-------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+-------------------------------------------+
| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+------------------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql>
配置文件my.ini
[mysqld]
设置3306端口
port=3306
设置mysql的安装目录
basedir=C:\Program Files\MySQL
设置mysql数据库的数据的存放目录
datadir=E:\database\MySQL\Data
允许最大连接数
max_connections=200
允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
服务端使用的字符集默认为UTF8
character-set-server=utf8
创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
设置mysql客户端默认字符集
default-character-set=utf8
[client]
设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
初始化数据库
mysqld –initialize –console
注意!执行输出结果里面有一段: [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rI5rvf5x5G,E 其中root@localhost:后面的“rI5rvf5x5G,E”就是初始密码(不含首位空格)。在没有更改密码前,需要记住这个密码,后续登录需要用到。
安装服务
mysqld –install
net start mysql
mysql -uroot -p;sHD)Yjrd9kr
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘root’;
show database;