MySQL 5.7.26安装及配置--windows10系统下

安装过程省略,下载包解压即可
https://dev.mysql.com/downloads/mysql/5.7.html

一、配置my.ini
在解压目录下,新建一个my.ini

[mysql]
; 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
;设置3306端口
port=3306
; 设置mysql的安装目录
basedir=E:\mysql-5.7.26-winx64
; 设置mysql数据库的数据的存放目录
datadir=E:\mysql-5.7.26-winx64\data
; 允许最大连接数
max_connections=200
; 服务端使用的字符集
character-set-server=utf8
; 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
; 关闭默认ssl连接--20210602添加
skip_ssl

二、安装mysql服务
以管理员身份打开cmd窗口后,将目录切换到你的解压文件bin目录下
执行:mysqld install

E:\mysql-5.7.26-winx64\bin>mysqld install
Service successfully installed.

三、初始化data目录
执行:mysqld --initialize
会生成data目录

E:\mysql-5.7.26-winx64\bin>mysqld --initialize

如果提示:由于找不到MSVCR120.dll,无法继续执行代码
参考:https://blog.csdn.net/will__be/article/details/106826534

四、启动服务
执行:net start mysql

E:\mysql-5.7.26-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。

服务没有报告任何错误。

请键入 NET HELPMSG 3534 以获得更多的帮助。

日志在data目录下
查看错误日志DESKTOP-PB5DAU8.eer,报错如下:
2019-05-22T05:28:58.435211Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2019-05-22T05:28:58.435633Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2019-05-22T05:28:58.435986Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-05-22T05:28:58.637803Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-05-22T05:28:58.638181Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-05-22T05:28:58.638504Z 0 [ERROR] Failed to initialize builtin plugins.
2019-05-22T05:28:58.638779Z 0 [ERROR] Aborting

解决办法是结束mysqld.exe进程,删除data目录,手工建立data目录,重新执行mysqld --initialize,然后启动mysql
(推测可能由于mysql自己生成的data目录没有权限,需要手工建立才行)

E:\mysql-5.7.26-winx64\bin>mysqld --initialize

E:\mysql-5.7.26-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

五、登陆mysql
在DESKTOP-PB5DAU8.err日志中,找到root用户临时密码:

2019-05-22T06:41:22.765339Z 1 [Note] A temporary password is generated for root@localhost: 1j3qx1ZjAK-Y

执行:mysql -u root -p

E:\mysql-5.7.26-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26

Copyright (c) 2000, 2019, 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>

六、修改root用户密码
修改密码后,退出重新登陆

mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

七、创建数据库和用户
1、创建用户
1)本地登录

create user 'user1'@'localhost' identified by '654321';

2)可以远程登录

create user 'user2'@'%' identified by '654321';

2、创建数据库
1)使用默认字符集

create database webapp;

2)指定字符集

create database webapp2 default charset utf8 collate utf8_general_ci;

3、授权用户权限
1)授权用户对某个数据库部分权限

grant select,update,delete,create on webapp.* to 'user1'@'localhost';

2)授权用户对某个数据库所有权限

grant all privileges on webapp2.* to 'user2'@'%';

4、查看数据库

show databases;

5、查看用户

select user,host,authentication_string from mysql.user;

参考资料:
https://www.cnblogs.com/GaoNa/p/9352105.html
https://blog.csdn.net/qq493820798/article/details/80101576
https://blog.csdn.net/memory6364/article/details/82426052

新建用户:
create user 'xxljob'@'%' identified by '654321';
create database xxl_job default charset utf8 collate utf8_general_ci;
grant all privileges on xxl_job.* to 'xxljob'@'%';

create user 'user3'@'%' identified by '654321';
create database shop default charset utf8 collate utf8_general_ci;
grant all privileges on shop.* to 'user3'@'%';

新建utf8mb4数据库:
create database gjzg default charset utf8mb4 collate utf8mb4_general_ci;
grant all privileges on gjzg.* to 'gjzg'@'%';

create database gjzg_dc default charset utf8mb4 collate utf8mb4_general_ci;
grant all privileges on gjzg_dc.* to 'gjzg_dc'@'%';

create database gjzg_release default charset utf8mb4 collate utf8mb4_general_ci;
grant all privileges on gjzg_release.* to 'gjzg_release'@'%';
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值