Mysql-winx64 安装教程

转自

keyword: MySQL   数据库

————————————————————

1.下载

https://dev.mysql.com/downloads/mysql/

解压到自己喜欢的一个位置即可(目录中不要包含中文)

如:D:\Program Files\

2.系统环境变量配置

       (1)新增系统变量  

                  变量名:MYSQL_HOME                   变量值:Mysql解压目录,如D:\Program Files\mysql-5.7.21-winx64         (2)追加PATH                     ;%MYSQL_HOME%\bin;

3.配置my.ini文件

在解压根目录新建一个my.ini的文件

  1.   # For advice on how to change settings please see
  2.   # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
  3.   # *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
  4.   # *** default location during install, and will be replaced if you
  5.   # *** upgrade to a newer version of MySQL.
  6.    
  7.   [mysqld]
  8.    
  9.   # Remove leading # and set to the amount of RAM for the most important data
  10.   # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  11.   # innodb_buffer_pool_size = 128M
  12.    
  13.   # Remove leading # to turn on a very important data integrity option: logging
  14.   # changes to the binary log between backups.
  15.   # log_bin
  16.    
  17.   # These are commonly set, remove the # and set as required.
  18.   basedir = “D:\\Program Files\mysql-5.7.21-winx64”
  19.   datadir = “D:\\Program Files\mysql-5.7.21-winx64\data”
  20.   port = 3306
  21.   character_set_server = utf8
  22.    
  23.   # server_id = …..
  24.    
  25.    
  26.   # Remove leading # to set options mainly useful for reporting servers.
  27.   # The server defaults are faster for transactions and fast SELECTs.
  28.   # Adjust sizes as needed, experiment to find the optimal values.
  29.   # join_buffer_size = 128M
  30.   # sort_buffer_size = 2M
  31.   # read_rnd_buffer_size = 2M
  32.    
  33.   sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


4.管理员方式启动命令提示窗符

进入mysql解压目录到bin目录下

如:D:\Program Files\mysql-5.7.21-winx64\bin

分别执行:

(1)初始化:mysqld -initialize-insecure

如果报错failed to set datadir to 则 执行一下  mysqld –initialize –user=mysql –console,再执行(1);

正确之后会在Mysql解压根目录生成data文件夹以及相关文件

(2)mysqld -install

*如提示Install/Remove of the Service Denied,说明不是已管理员的方式进入的命令提示符

(3)启动服务:net start mysql

(4)登陆,改密码 mysql -u root -p 

【成功登陆的直接到(5)】

我的出现了

在my.ini中增加

重启服务,成功登陆

(5)执行改密码语句 (正常登陆的使用set password= password(‘新密码’);)

update user set authentication_string = password(“新密码”) where user=‘root‘;

(6)exit;  net stop mysql

(7)登陆成功的忽略这一步

到my.ini中注释掉

重启进入之后set password= password(‘新密码’);

到此就可以正常使用了。

(8)测试 show databases;

5.写两个bat文件用于启动和关闭mysql服务

(1)启动mysql服务

  1.   @echo off
  2.   echo 确定要启动MySQL服务吗?
  3.   pause
  4.   net start mysql
  5.   echo 启动MySQL服务完成,请确认有没有错误发生。
  6.   Pause

保存为   mysql服务启动.bat   文件,运行时要以管理员方式运行
(2)关闭mysql服务

  1.   @echo off
  2.   echo 确定要关闭MySQL服务吗?
  3.   pause
  4.   net stop mysql
  5.   echo 关闭MySQL服务完成,请确认有没有错误发生。
  6.   Pause

保存为   mysql服务关闭.bat   文件,运行时要以管理员方式运行

MySql到此安装结束。