Mysql 5.7 免安装版安装配置教程

时间:2021-06-28 16:10:52

1、填写配置文件参数:

    mysql解压后,主文件中自带my-defaul.ini 配置文件,复制一份该文件并重命名为my.ini,

 原配置文件  my-default.ini内容

  # For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.


[mysqld]


# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin


# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....




# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


修改my.ini后内容:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.


[mysqld]


# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
 innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin


# These are commonly set, remove the # and set as required.
#设置mysql安装目录路径
 basedir = D:\Program Files\mysql-5.7.16-winx64
#设置mysql数据文件夹路径
 datadir = D:\Program Files\mysql-5.7.16-winx64\data
#设置mysql端口
 port = 3306
#设置mysql server_id
 server_id = 1




# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
 join_buffer_size = 128M
 sort_buffer_size = 2M
 read_rnd_buffer_size = 2M 


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


2、配置mysql bin目录的环境变量到path:

  例如:我的环境变量就是: path -> D:\Program Files\mysql-5.7.16-winx64\bin


3、wind + R 打开命令行界面,输入相关命令:

 注意:第一次使用安装mysql 5.7版本的时候,若发现因根目录下,缺少data文件夹的情况(mysql 5.7版本开始不自带data文件夹,需要自己创建),请不要去拷贝其他版本的data文件夹;因为此操作会出现很多潜在问题:比如我遇到的执行show variables like "%charact%"; 语句时,报错表不存在!

打开cmd命令窗口,并且进入到mysql安装目录的bin目录下。然后输入命令:
mysqld --initialize-insecure --user=mysql
然后回车;去目录下查看,已经自动创建好data文件夹。

开启mysql过程:

          注册mysql服务: mysqld --install

         开启mysql服务: net start mysql

关闭mysql过程:

         关闭mysql服务: net stop mysql

        移除mysql注册: mysqld --remove


4、修改mysql密码:

     4.1 mysql 5.7版本以前修改root密码的方法:

              mysql -u root
  mysql> use mysql;
  mysql> update user set password = PASSWORD('123') where user = 'root';
  mysql> flush privileges; 
       mysql>quit

    4.2 mysql 5.7版本修改root密码方法: 

   mysql -u root
mysql> use mysql;
mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
mysql> flush privileges; 
mysql>quit

*特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了
而是将加密后的用户密码存储于authentication_string字段


5、查看mysql 版本:

        mysql --version


6、命令行登陆mysql:

        未设置密码时:mysql -u root 

        设置密码时:mysql -u root -p                  //在配置环境变量后任意路径下输入此命令

                             Enter password:                //输入之前设置的mysql数据库密码


7、mysql 发生系统错误2,产生原因以及解决方案:

   原因:发生这个系统错误2 的原因是mysql默认配置是认为安装目录是  C:\Program Files\mysql-5.7.16-                             winx64\bin,但实际上我们安装的时候大多数是安装在D盘的,导致识别不到;

 解决方案:到mysql的实际安装目录的bin文件下去执行mysql的相关命令;