MySQL 5.7.26安装与卸载

环境:

  win10(本地)

  MySQL版本:mysql-5.7.26-winx64

 

一、卸载

1.停止MySQL服务
2.删除MySQL安装目录
3.清理MySQL相关注册表
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/Eventlog/Application/MySQL 
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet002/Services/Eventlog/Application/MySQL 
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Eventlog/Application/MySQL
如果没有相应的文件夹,就不用删除;最后Ctrl+F输入MySQL再次查找一遍,能找到相关的注册信息就删除
4.重启

 

 二、安装

1.去Oracle官网下载社区版(mysql-5.7.26-winx64.zip解压版)

 MySQL下载地址:https://downloads.mysql.com/archives/community/

2.解压下载的文件(这里解压到了D:\MySQL-5.7.26)

--MySQL-5.7.26
  |--bin
  |--docs
  |--include
  |--lib
  |--share
  |--COPYING
  |--README

3.创建数据的存放目录data,为MySQL新增配置信息my.ini

在D:\MySQL-5.7.26创建数据存放目录data,新建配置文件my.ini

--MySQL-5.7.26
  |--bin
  |--docs
  |--data
  |--include
  |--lib
  |--share
  |--COPYING
  |--README
  |--my.ini

my.ini内容添加如下(简单版配置):

[client]
#设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8

[mysqld]
#设置3306端口
port=3306
#设置mysql的安装目录
basedir=D:\MySQL-5.7.26
#设置mysql数据库的数据的存放目录
datadir=D:\MySQL-5.7.26\data
#允许最大连接数
max_connections=200
#允许连接失败的次数,防止有人从该主机试图攻击数据库系统
max_connect_errors=10
#服务端使用的字符集默认为UTF8(默认为8比特编码的latin1字符集)
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#默认使用mysql_native_password插件认证(可以使用除mysql.user系统表之外的凭据的身份验证,如PAM,Windows登录ID,LDAP或Kerberos)
default_authentication_plugin=mysql_native_password
#忘记密码时使用
#skip-grant-tables

4.以管理员身份调出powershell命令行终端界面

5.将目录切换到MySQL解压bin目录下,执行 mysqld install,安装MySQl服务

PS C:\WINDOWS\system32> cd D:\MySQL-5.7.26\bin\
PS D:\MySQL-5.7.26\bin> .\mysqld.exe install
Service successfully installed.
结果显示Service successfully installed服务安装成功

6.初始化data目录

PS D:\MySQL-5.7.26\bin> .\mysqld.exe --initialize-insecure

(注:mysqld --initialize-insecure自动生成无密码的root用户,mysqld --initialize自动生成带随机密码的root用户) 

7.net start mysql启动MySQL服务

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

8.修改root用户密码

PS D:\MySQL-5.7.26\bin> .\mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26 MySQL Community Server (GPL)

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> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

9. 给root用户开启远程访问权限

为了方便,设置好MySQL环境变量后执行

#连接数据库
PS C:\Users\cchengyyj> mysql -uroot -p
Enter password: ******
#使用mysql库
mysql> use mysql;
Database changed
#查询用户表命令
mysql> select  User,authentication_string,Host from user;
+---------------+-------------------------------------------+-----------+
| User          | authentication_string                     | Host      |
+---------------+-------------------------------------------+-----------+
| root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
+---------------+-------------------------------------------+-----------+
3 rows in set (0.00 sec)
#授权远程登陆
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#再次查询用户表命令
mysql> select  User,authentication_string,Host from user;
+---------------+-------------------------------------------+-----------+
| User          | authentication_string                     | Host      |
+---------------+-------------------------------------------+-----------+
| root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | %         |
+---------------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)

 

posted @ 2019-09-18 18:06  youngyajun  阅读(2494)  评论(0编辑  收藏  举报