当前位置:   article > 正文

MySql 下载 + 安装笔记_mysql-8.3.0-winx64

mysql-8.3.0-winx64

下载

下载页面:https://dev.mysql.com/downloads/mysql
MySql 5.7下载链接 :
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-winx64.zip
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
MySql8.0下载链接 :
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.15-winx64.zip
在这里插入图片描述 在这里插入图片描述

再给个国内镜像
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads

WIN 安装

  • 解压到D盘比如: D:\mysql5.7D:\mysql8.0 如果本机只安装一个版本就直接用 D:\mysql
  • D:\mysql\bin 路径追加进环境变量 path
  • 在新建文件夹 D:\mysql\data (有人又说不要创建,让mysql初始化时自动生成)
  • 修改配置文件 D:\mysql\my.ini 从MySQL 5.7.18开始,不再自带这个文件,自己创建就行了
# 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=d:\mysql
datadir=d:\mysql\data
# 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 
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

参考

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=d:\\mysql
datadir=d:\\mysql\\data
# 允许最大连接数
max_connections=200
# 允许最大连接人数
max_user_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

安装命令

  • 管理员身份运行cmd
# 进入 D 盘
C:\Users\Administrator>d: 
# 进入mysql的bin 目录
D:\>cd mysql/bin
# 初始化. 
# --initialize 随机密码
# --initialize-insecure 无密码
# --user指定所属用户
D:\mysql\bin>mysqld --initialize-insecure --user=mysql
# 安装:默认的服务名是 mysql 
D:\mysql\bin> mysqld install
# 启动 mysql
D:\mysql\bin>net start mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

删除服务

# 关闭服务
net start mysql
# 删除服务
mysqld -remove mysql
  • 1
  • 2
  • 3
  • 4

装多个MySQL

在已经装了 mysql5.7 后,再装 mysql8.xD:\mysql-8.0.31-winx64
记得使用绝对路径。

# 这次 mysqld 用了绝对路径
D:\>D:\mysql-8.0.31-winx64\bin\mysqld --initialize-insecure --user=mysql
# 安装:
# 默认的服务名是 mysql 
# 如果同时装多个MySQL,会需要手动指定服务名。比如 MySQL8。
# 指定配置文件 --defaults-file=D:\mysql-8.0.31-winx64\my.ini
D:\>D:\mysql-8.0.31-winx64\bin\mysqld install MySQL8
# 启动 mysql
D:\mysql\bin>net start mysql8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

如果没用绝对路径

可能装好后会发现还是 5.7x 的路径。
在这里插入图片描述 在这里插入图片描述

正确安装

在这里插入图片描述

登陆失败处理

命令行登录失败

mysql -u 用户名 -p密码 [数据库名]
  • 1

在这里插入图片描述

Navicat登录失败

在这里插入图片描述
在这里插入图片描述

换个新版本的 Navicat 即可

在这里插入图片描述

修改密码

  • 5.7版本以前
update user set password=password(“新密码”) where user=”用户名”;
  • 1
  • 5.7版本以后
use mysql # 选择数据库
# 修改密码(密码)
update mysql.user set authentication_string=PASSWORD('123456') where User='root';// root密码改为123456
update mysql.user set authentication_string=password('root') where user='root';// root密码改为root
flush privileges; #刷新
  • 1
  • 2
  • 3
  • 4
  • 5

如果是忘记密码进不了MySQL

  1. 管理员身份运行cmd
  2. 先停掉mysql服务:net stop mysql
  3. (如果配了环境变量跳过这步)到MySQL安装路径下:D:\mysql-5.7.16-winx64\bin
  4. 输入命令mysqld -nt --skip-grant-tables
  5. 另开一个管理员cmd输入:mysql -uroot -p回车,密码不用填回车,即可进入数据库。

Linux 安装 (rpm)

环境描述
操作系统CentOS7 64位
MySQLMySQL5.7

1、配置YUM源

在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/
在这里插入图片描述

# 下载mysql源安装包
[jerryjin@localhost 下载]$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
[jerryjin@localhost 下载]$ sudo yum localinstall mysql57-community-release-el7-8.noarch.rpm
# 检查mysql源是否安装成功
[jerryjin@localhost 下载]$  yum repolist enabled | grep "mysql.*-community.*"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

成功显示如下:

mysql-connectors-community/x86_64       MySQL Connectors Community           108
mysql-tools-community/x86_64            MySQL Tools Community                 90
mysql57-community/x86_64                MySQL 5.7 Community Server           347
  • 1
  • 2
  • 3

在这里插入图片描述
我们要安装 mysql5.7 检查一下

[jerryjin@localhost 下载]$  cat /etc/yum.repos.d/mysql-community.repo
  • 1

看到 [mysql57-community]enabled=1 其他版本enabled=0正合我意,不用改了。如果不是我们vim进去改一改

2、安装 mysql

[jerryjin@localhost 下载]$  sudo yum install mysql-community-server
... 
# 一通跑后列出我要下载 194M 的东西。输入y回车即可。
Total download size: 194 M
Is this ok [y/d/N]: y
# 下载完后 Retrieving key 还会问一次,我不懂。输入y回车继续
# 然后就是一通安装的信息,最后就成功了
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 如果报错:
    Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
    GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

重新导入秘钥

[jerryjin@localhost 下载]$  rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  • 1

然后再执行 安装命令即可

[jerryjin@localhost 下载]$  sudo yum install mysql-community-server
  • 1

3、MySQL 初始配置

启动MySQL服务

[jerryjin@localhost 下载]$ systemctl start mysqld
  • 1

查看状态。

[jerryjin@localhost 下载]$ systemctl status mysqld
  • 1

能看到绿色的 active (running) 表示成功

开机启动

[jerryjin@localhost 下载]$ systemctl enable mysqld
[jerryjin@localhost 下载]$ systemctl daemon-reload
  • 1
  • 2

修改root本地登录密码

初始生成的默认密码记录在/var/log/mysqld.log。我们找出来:

[jerryjin@localhost 下载]$ grep 'temporary password' /var/log/mysqld.log
  • 1

在这里插入图片描述

登录 MySQL

[jerryjin@localhost 下载]$ mysql -uroot -py>kjl5&Qwq_m
  • 1

修改密码

目前远程登录还没实现,以下是在本机上操作:

  • 关闭密码则略
    mysql5.7为了让你记不住密码,默认开了密码策略。我只是内网学习,关掉它再说。 向配置中添加validate_password = off
[jerryjin@localhost 下载]$ sudo vim /etc/my.cnf
  • 1

重启mysql生效

[jerryjin@localhost 下载]$ systemctl restart mysqld
  • 1
  • 修改本地账户root密码为root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'
  • 1

实现远程登录

mysql默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,要么修改root允许远程连接。接下来我必须去本机操作了23333

mysql> select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

没修改默认密码前做以下操作,系统会提示你先改密码。

  • root允许远程连接(也只有自己玩时能这么
    百分号%表示允许所有机器访问,可以替换成ip
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
  • 1
mysql> select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

成功后就可以远程登录了

[jerryjin@localhost 下载]$ mysql -h 192.168.31.37 -uroot -proot
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 4
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'jerryjin'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.32 sec)
  • 1
  • 2
mysql> select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| jerryjin      | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

配置默认编码为utf8 (utf8md4)

两种方法查看:
mysql> status;
在这里插入图片描述
mysql> show variables like’char%’;
在这里插入图片描述
配置文件 /etc/my.cnf 添加
mysql 中的一个坑 utf8mb4 才是真utf8 。详细介绍看:MySQL 的 utf8 和 utf8mb4 请使用 utf8mb4

[client]
default_character_set=utf8mb4
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8mb4
  • 1
  • 2
  • 3
  • 4
  • 5

重启mysql生效

[jerryjin@localhost 下载]$ systemctl restart mysqld
  • 1

忽略表名大小写

官网文档 9.2.3 Identifier Case Sensitivity
0 表名按原大小写存,读的时候区分大小写
1 表名按小写存,读时按小写取(忽略大小写了
2 表名按原大小写存,但是读的时候都自动转小写再用

如果已经有表存在,直接改这个会启动不了,因为之前的表会无法识别。可以先全导出,改后重启,再导入。

[mysqld]
lower_case_table_names=1
  • 1
  • 2

完整配置 /etc/my.cnf

[client]
default_character_set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password = off

collation_server = utf8_general_ci
character_set_server = utf8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

5、防火墙开放 3306

# 1. 查看 3306 是否在工作
netstat -ntulp | grep 3306 
	# tcp6       0      0 :::3306                 :::*              LISTEN      28182/mysqld 
# 2. 查看防火墙已经开放的端口
firewall-cmd --list-ports
# 3. 防火墙开放 3306 端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 4. 重启防火墙生效
firewall-cmd --reload
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

查看端口

mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set, 1 warning (0.01 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参考资料

笑虾:MySQL 忘记密码 / 修改密码 / 找回密码

MySQL5.7安装与配置(YUM)
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
linux centos7下源码 tar安装mysql5.7.22或mysql5.7.20 图文详解
MySQL 安装 | 菜鸟教程

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/301188
推荐阅读
相关标签
  

闽ICP备14008679号