MySQL解压版安装配置

MySQL解压后遇到的一些问题总结

运行环境

  • Windows: Windows 7
  • MySQL版本: mysql-8.0.11-winx64

环境配置

文件解压

  • 解压后的路径: D:\Program Files (x86)\mysql-8.0.11-winx64

系统环境变量

  • 新建MYSQL_HOME:D:\Program Files (x86)\mysql-8.0.11-winx64;
  • 添加PATH:%MYSQL_HOME%\bin;

或者

  • 添加PATH: D:\Program Files (x86)\mysql-8.0.11-winx64\bin

**注:**选择两种方式中的一种都可以(对后续步骤无影响),根据自身喜好决定

MySQL配置

配置文件

  • D:\Program Files (x86)\mysql-8.0.11-winx64(本地MySQL安装路径)下新建my.ini.txt名字的文件(文件名及文件格式需一致)。
# 设置端口号
port=3306
# 设置MySQL安装路径
basedir=D:\Program Files (x86)\mysql-8.0.11-winx64
# 设置MySQL数据库的存放目录
datadir=D:\Program Files (x86)\mysql-8.0.11-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数
max_connect_errors=10
# 服务端使用的字符集默认为UTF-8
character-set-server=utf8
# 创建新表时将使用默认的存储引擎
default-storage-engine=INNODB
# 使用默认时区为东八区
default-time-zone='+8:00'
# 密码
# root@localhost: &i4heQcySo;L

执行MySQL安装命令

  • 使用管理员权限运行CMD,进入MySQL安装路径
mysqld --install mysql

注:

  1. 如果之前有安装其他版本的mysql服务器名称,可以使用mysql-versionmysql后添加自定义的版本名称区分开;可选择删除之前的版本,mysqld remove mysql;
  2. 安装时会生成初始化密码,密码在root@localhost:的后面(需要及时保存,后续需要登录MySQL修改密码)。
  • 再次启动服务器
net start mysql
  • 如果出现ERROR 1130 (HY000): Host 'xx-PC' is not allowed to connect to this MySQL server类似错误,后续有解决方法

修改密码

  • 新开一个CMD窗口,进入安装MySQL_HOME\bin的路径,
D:\Program Files (x86)\mysql-8.0.11-winx64\bin>mysql -uroot -p # 使用临时密码登录
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.11 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> use mysql
Database changed
mysql> alter user user() identified by 'root';
  • 之后便能使用root@localhost: root账号和密码登录了,当前设置密码为root可以自行修改

解决问题

ERROR 1130 (HY000): Host 'xx-PC' is not allowed to connect to this MySQL server

这是因为MySQL用的是电脑的名字登录,而不是数据库初始化默认的localhost地址。

解决方法

  • 管理员启动CMD并进入D:\Program Files (x86)\mysql-8.0.11-winx64\bin>执行下列语句,使用跳过验证的方式启动mysql
D:\Program Files (x86)\mysql-8.0.11-winx64\bin>mysqld --console --skip-grant-tables --shared-memory
  • 新开一个CMD窗口,使用mysql -uroot -p登录;然后修改user表内的root用户信息;将root账号host改为对应的账号名字(有可能你的并不是xx-PC,这个要根据实际情况调整)

  • 执行SQL

mysql> update user set host='xxx-PC' where user='root';
Query OK, 1 row affected (0.12 sec)
Rows matched: 1  Changed: 1  Warnings: 0

修改之前

mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost  | root             |
+-----------+------------------+

修改之后

mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | dew              |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| xxx-PC  | root             |
+-----------+------------------+
  • 改完之后就能使用net start mysql语句启动后使用root@xxx-PC的方式连接数据库了;可以新建一个账号实现localhost的登录。

创建数据库登录用户的SQL

create user 'dew'@'localhost' identified by 'root';

ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

  • mysql -uroot -p登陆出现该错误

解决方案

  1. 删除mysql-8.0.26\data目录
  2. CMD管理员运行mysqld --initialize --user=mysql --console
  3. 获取临时密码后执行文章内的修改密码步骤,即可使用新设置的密码登陆。

注: 希望我记录的解决方法能帮到你,如果你在实际过程中遇到其他的问题。可以在文章下留言,我看到后会及时回复。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值