1. 根目录下创建my.ini文件,并添加如下配置
[mysqld]
basedir = D:\JAVASOFTWARE\mysql-8.0.20-winx64
datadir = D:\JAVASOFTWARE\mysql-8.0.20-winx64\data
port = 3306
character-set-server = utf8
#因为8.0的新特性caching_sha2_password,导致Navicat不能正常链接
default_authentication_plugin=mysql_native_password
max_connections=200
default-storage-engine=INNODB
[mysql]
default-character-set = utf8
[client]
default-character-set = utf8
2. 配置环境变量 , 当然如果喜欢来回敲路径可以忽略
%path%;D:\JAVASOFTWARE\mysql-8.0.20-winx64\bin\
3. 初始化命令
1). mysqld --initialize --console // 带默认密码
2). mysqld --initialize-insecure --console // 不带默认密码
报错:由于找不到VCRUNTIME140_1.dll,无法继续执行代码
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads 下载安装
成功后控制台上有初始化密码: A temporary password is generated for root@localhost: Z9l.xBtIPaXQ
4. 安装成windows服务(cmd用管理员身份启动)。
mysqld --install mysql
启动服务 (1). net start mysql (2).window 服务右键启动服务, 两种方式,你喜欢就好。
5. 修改root密码:
alter user root@localhost identified by '123';
flush privileges;
6. 添加Navicat连接权限
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
PS: extends
1. 创建用户:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
2. 添加权限:
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
grant all on db.tablename to 'username'@'host'