mysql5.7通过文件zip方式安装-九五小庞
为什么通过zip的方式进行安装
电脑上已安装过mysql数据库,想要再安装一个。
1.下载mysql安装包
直接找到mysql官网,在官网上下载zip安装包。
https://downloads.mysql.com/archives/community/
解压完成后是这个样子的(注意:解压完的文件放到一个合适的地方,不要乱放)
2.在mysql-5.7.38-winx64安装包中创建my.ini文件,创建data文件夹
[mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] #skip-grant-tables #设置3310端口 port = 3310 #关闭ONLY_FULL_GROUP_BY sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' # 设置mysql的安装目录 basedir=G:\Program Files\mysql-5.7.37-winx64 # 设置mysql数据库的数据的存放目录 datadir=G:\Program Files\mysql-5.7.37-winx64\data # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB
3.初始化mysql数据库
以管理员身份打开命令行
切换到mysql安装包的目录下
执行 mysqld --initialize
初始化, 然后发现data文件夹多了mysql的文件夹,也就意味着数据库正常生成了
4.安装服务
在mysql安装包目录下创建bat文件
@set mysql_service="G:\Program Files\mysql-5.7.37-winx64\bin\mysqld.exe" ::设置服务名 @set service_name="MYSQL57" ::安装服务 %mysql_service% --install %service_name% --defaults-file="G:\Program Files\mysql-5.7.37-winx64\my.ini" pause
然后以管理员身份运行【安装.bat】
安装成功后,在电脑服务中会有一个MYSQL57服务(注意,如果服务没有启动,需要手动启动一下服务)
5.修改root管理员密码和权限
修改my.ini文件,在[mysqld]节点中加上 skip-grant-tables参数
说明:skip-grant-tables参数的作用是,通过root用户登录数据库,不需要输入密码,直接绕过密码
改完配置后,记得需要重启一下mysql57服务
连接上mysql数据库,进行修改
G:\Program Files\mysql-5.7.37-winx64\bin>mysql -u root -p123456 -P 3310 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.37 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> flush privileges; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit
修改root用户的链接访问权限
![](https://img2022.cnblogs.com/blog/1943666/202207/1943666-20220726125905841-1654894943.png)
G:\Program Files\mysql-5.7.37-winx64\bin>mysql -u root -p123456 -P 3310 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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> select host, user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 3 rows in set (0.00 sec) mysql> update user set host = '%' where user = 'root' and host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host, user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | root | | localhost | mysql.session | | localhost | mysql.sys | +-----------+---------------+ 3 rows in set (0.00 sec) mysql> quit Bye