注:以下经常提到的data目录为,安装MySQL时自动生成,不能手动创建,否则报错(重复报错也会报错)
一、下载MySQL
5.7版本:MySQL :: Begin Your Download
8.0版本:MySQL :: Download MySQL Community Server
二、配置my.ini【环境变量】
1、(最外层目录下、其他版本为my.cnf)文件(主要路径问题,如果路径不正确,无法新建data文件)
2、两个端口需要替换,并且是一样
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 #utf8mb4
[mysqld]
#设置3306端口
port = 13307
# 设置mysql的安装目录
basedir=E:\mysql-5.7.27-winx64
# 设置mysql数据库的数据的存放目录
datadir=E:\mysql-5.7.27-winx64\data
# 允许最大连接数
max_connections=2000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
[client]
port=13308
[mysql]
default-character-set=utf8 #utf8mb4
[mysqld]
port=13308
skip-grant-tables
basedir=D:\Programming\mysql-5.7.26-winx64
datadir=D:\Programming\mysql-5.7.26-winx64\data
character-set-server=utf8
default-storage-engine=INNODB
max_connections=500
query_cache_size=50M
tmp_table_size=500M
thread_cache_size=8
max_allowed_packet=50000M
key_buffer_size=30M
read_buffer_size=100M
read_rnd_buffer_size=100M
sort_buffer_size=4096K
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=4M
innodb_buffer_pool_size=50M
innodb_thread_concurrency=8
innodb_flush_log_at_trx_commit=2
wait_timeout=2147483
interactive_timeout =2147483
default-time-zone=timezone
default-time-zone='+8:00'
三、执行命令
3.1、打开dos窗口,以管理员方式进入到bin目录
3.2、安装命令:mysqld --install xxx (卸载命令:mysqld --remove xxx 或 sc delete MySQL xxx)
3.3、初始化MySQL:mysqld --initialize-insecure 或者 mysqld --initialize --console 会生成data文件(注意此处保存密码,如果没打印出来密码就是空)
3.4、启动服务:net start xxx (停止:net stop xxx
3.5、进入mysql命令(创建data时已生成密码): mysql-5.7.27-winx64\bin> mysql -u root -p
3.6、修改密码:alter user user() identified by '******';
或者 update mysql.user set password=PASSWORD('******') where User='******';
或者 update mysql.user set authentication_string=password('*******') where user='*******';
刷新权限:flush privileges;
重启服务中的MySQL
四、一定要确认已经启动才可以
五、使用Navicat Premium11连接数据库异常
报错:is not allowed to connect to this mysql server
原因:权限不够,只允许本机访问
六、一台电脑(windows)安装两个版本MYSQL方法
========================================以下报错解决方法=======================================
1、'mysqld' 不是内部或外部命令,也不是可运行的程序
原因:没有配置环境变量
在环境变量中的用户变量选择“Path”,单击编辑,将MySQL中bin的安装路径,粘贴到此处,即可。
“系统变量(S)”里,配置“MYSQL_HOME”变量
2、 (0xc000007b) 代码错误
下载DirectX修复工具 DirectX修复工具增强版-DirectX修复工具下载 v4.0.0.0增强版--pc6下载站
3、缺少msvcr120.dll文件
下载文件msvcr120.dll下载-msvcr120.dll正式版下载[电脑版]-华军软件园
4、输入mysqld --initialize-insecure 命令报以下错误
1)
D:\mysql-5.7.27-13307\bin>mysqld --initialize-insecure
mysqld: Can't create directory 'D:\mysql-5.7.27-winx64\data\' (Errcode: 2 - No s
uch file or directory)
2019-09-02T07:07:03.185182Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2019-09-02T07:07:03.220339Z 0 [ERROR] Can't find error-message file 'D:\mysql-5.
7.27-winx64\share\errmsg.sys'. Check error-message file location and 'lc-message
s-dir' configuration directive.
2019-09-02T07:07:03.292608Z 0 [ERROR] Aborting
原因my.ini文件的路径不匹配,无法创建data文件夹(查看第2点)
2)
2019-09-02T07:23:08.176337Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-09-02T07:23:08.276927Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-09-02T07:23:08.277904Z 0 [ERROR] Aborting
原因:在my.ini文件中添加 explicit_defaults_for_timestamp=true 放在mysqld下
3)
2019-09-02T07:33:58.913239Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-09-02T07:33:58.918122Z 0 [ERROR] Aborting
原因:
已经初始化,但没有成功,想再次初始化报错。
解决:
数据文件目录有其他的文件,这个data目录应该是一个空目录;
查看data目录是哪个,把data文件删除。
5、ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
6、Install/Remove of the Service Denied!
原因:没有权限
解决办法:打开cmd.exe程序的时候选择“用管理员身份打开”。
7、ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statemen
mysql 配置文件目录:/etc/my.cnf
root 密码为空的时候配置文件中下面这句:skip-grant-tables
8、相关命令
variables like "secure_file_priv"; //查看secure_file_priv是否为null
flush privilegesshow //刷新权限、主机等
9、windows安装mysql 遇到错误193的解决办法
10、Client does not support authtication protocol..consider upgrading mysql client