MySQL
解压后遇到的一些问题总结
MySQL
下载路径:https://dev.mysql.com/downloads/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
注:
- 如果之前有安装其他版本的
mysql
服务器名称,可以使用mysql-version
在mysql
后添加自定义的版本名称区分开;可选择删除之前的版本,mysqld remove mysql
; - 安装时会生成初始化密码,密码在
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
登陆出现该错误
解决方案
- 删除
mysql-8.0.26\data
目录 CMD
管理员运行mysqld --initialize --user=mysql --console
- 获取临时密码后执行文章内的修改密码步骤,即可使用新设置的密码登陆。
注: 希望我记录的解决方法能帮到你,如果你在实际过程中遇到其他的问题。可以在文章下留言,我看到后会及时回复。