window mysql 安装步骤

  • 社区版本下载地址: https://dev.mysql.com/downloads/file/?id=474802

  • 下载完成后,得到mysql-installer-web-community-5.7.21.0.msi文件,双击安装

  • 进入安装界面,下一步

  • 勾选server only 或者 Developer Default都可以,这里勾选仅服务器形式安装,然后下一步

  • 点击execute后,等待下载完成并自动安装

  • 安装完成后,一直点击下一步,直到出现设置root用户密码的界面


  • 设置完密码后,继续下一步, 到如下页面后,若白色圆圈中都是绿色则代表成功,否则出现红色就说明本地环境有问题。默认数据端口就是3306

  • 打开开始mysql默认命令行客户端,测试是否安装成功


  • 至此,window环境下mysql安装完成

linux mysql 安装步骤

CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用MariaDB代替了,MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品

  • 卸载centos7自带的MariaDB

    [root@VM_0_9_centos ~]# yum list installed | grep mariadb #检查mariadb是否已安装
    Repository epel is listed more than once in the configuration
    mariadb-libs.x86_64 1:5.5.52-1.el7 @anaconda [root@VM_0_9_centos ~]# yum -y remove mariadb* #全部卸载
    Loaded plugins: fastestmirror, langpacks
    Repository epel is listed more than once in the configuration
    Resolving Dependencies
    --> Running transaction check
    ---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be erased
    --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
    --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
    --> Running transaction check
    ---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
    --> Finished Dependency Resolution
    ##########################省略中间部分####################
    Removed:
    mariadb-libs.x86_64 1:5.5.52-1.el7 Dependency Removed:
    postfix.x86_64 2:2.10.1-6.el7
    Complete!
  • 下载并安装mysql的YUM源

    • 下载mysql的yum源
    wget -P /home/wuzhazha http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
    • 安装mysql的YUM源
    rpm -ivh mysql57-community-release-el7-11.noarch.rpm
    [root@VM_0_9_centos home]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
    warning: mysql57-community-release-el7-11.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ################################# [100%]
    Updating / installing...
    1:mysql57-community-release-el7-11 ################################# [100%]
    • 检查mysql的YUM源是否安装成功
    yum repolist enabled | grep "mysql.*-community.*"
    [root@VM_0_9_centos home]# yum repolist enabled | grep "mysql.*-community.*"
    Repository epel is listed more than once in the configuration
    mysql-connectors-community/x86_64 MySQL Connectors Community 131
    mysql-tools-community/x86_64 MySQL Tools Community 100
    mysql57-community/x86_64 MySQL 5.7 Community Server 384

    看到上图所示表示安装成功

    • 查看mysql版本
    yum repolist all | grep mysql
    [root@VM_0_9_centos home]# yum repolist all | grep mysql
    Repository epel is listed more than once in the configuration
    mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
    mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
    mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
    mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
    mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 131
    mysql-connectors-community-source MySQL Connectors Community - disabled
    mysql-tools-community/x86_64 MySQL Tools Community enabled: 100
    mysql-tools-community-source MySQL Tools Community - Sourc disabled
    mysql-tools-preview/x86_64 MySQL Tools Preview disabled
    mysql-tools-preview-source MySQL Tools Preview - Source disabled
    mysql55-community/x86_64 MySQL 5.5 Community Server disabled
    mysql55-community-source MySQL 5.5 Community Server - disabled
    mysql56-community/x86_64 MySQL 5.6 Community Server disabled
    mysql56-community-source MySQL 5.6 Community Server - disabled
    mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 384
    mysql57-community-source MySQL 5.7 Community Server - disabled
    mysql80-community/x86_64 MySQL 8.0 Community Server disabled
    mysql80-community-source MySQL 8.0 Community Server - disabled

    可以看到,默认5.7是启用的版本。可以通过类似下面的语句来启动或禁用某些版本

    yum-config-manager --enable mysql57-community
    yum-config-manager --disable mysql56-community

    或者通过修改vim /etc/yum.repos.d/mysql-community.repo文件,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0,然后再将5.6源的enabled=0改成enabled=1即可 。

    注意,任何时候,只能启用一个版本 。查看当前的启用的 MySQL 版本:yum repolist enabled | grep mysql

    [root@VM_0_9_centos home]# yum repolist enabled | grep mysql
    Repository epel is listed more than once in the configuration
    mysql-connectors-community/x86_64 MySQL Connectors Community 131
    mysql-tools-community/x86_64 MySQL Tools Community 100
    mysql57-community/x86_64 MySQL 5.7 Community Server 384
  • 安装mysql

    安装过程中一直输入"y"就可以了,当出现下面的结果时,就代表mysql数据库安装成功

    yum install mysql-community-server
  • 启动mysql服务

    systemctl start mysqld
  • 进入mysql命令行

    [root@VM_0_9_centos ~]# mysql
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    出现上述错误,说明mysql安装完后给root用户生成了一个默认密码,所以你需要使用密码登录。

    为了加强安全性,MySQL5.7为root用户随机生成了一个密码,如果安装的是RPM包,则默认是在/var/log/mysqld.log中。

    [root@VM_0_9_centos ~]# grep 'temporary password' /var/log/mysqld.log
    2019-11-04T06:34:15.567040Z 1 [Note] A temporary password is generated for root@localhost: NsRSsti#+7Vw

    密码为NsRSsti#+7Vw

    [root@VM_0_9_centos ~]# mysql -uroot -pNsRSsti#+7Vw
    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.28 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>

    出现上述提示,则表示登录成功!

    接下来执行use mysql可能会出现如下错误

    mysql> use mysql
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    因此,在使用前就必须修改密码

  • 修改mysql密码

    alter user 'root'@'localhost' identified by '123456';
    # mysqladmin -u root password 'Root123456'
    #set password for 'root'@'localhost' = password('123456');

    可能出现如下问题

    mysql>alter user 'root'@'localhost' identified by 'Root123456';
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    这是由于设置的密码不符合当前的密码策略,两种处理方式:1.设置符合当前密码策略的复杂密码;2.修改策略,依然使用弱密码(自己玩的话就没啥所谓)

    这里就以方式2为例:

    密码策略主要跟 validate_password_policy 取值有关,默认取值为MEDIUM,

    密码长度主要跟validate_password_length取值有关,默认值为8

    更改两个策略,1是允许弱密码,2是更改默认的密码长度

    set global validate_password_policy=LOW;
    set global validate_password_length=6; #最小值为4,设置小于4也会被重置为4
    mysql> set global validate_password_policy=LOW;
    Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=6;
    Query OK, 0 rows affected (0.00 sec) mysql> SHOW VARIABLES LIKE 'validate_password%' #查看密码策略

    策略更改成功,继续修改密码

    mysql> alter user 'root'@'localhost' identified by 'Root123456';
    Query OK, 0 rows affected (0.00 sec)

    如上,修改密码成功!

  • 修改数据库字符集,默认latinl

    mysql> SHOW VARIABLES LIKE 'character%'

    默认服务器的字符器是 latin1 ,对中文不友好。修改 /etc/my.cnf 文件,添加字符集的设置

    [root@VM_0_9_centos ~]# vim  /etc/my.cnf 
    
    [mysql]
    default-character-set=utf8 # 添加部分 # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld]
    character_set_server=utf8 # 添加部分
    #
    # 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
    #
    # 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
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0 log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid

    修改完成后,重启mysql,systemctl restart mysqld

    如上,更改成功!

  • 需要开启远程访问(参考)

    • 防火墙设置
    #远程访问 MySQL, 需开放默认端口号 3306
    firewall-cmd --permanent --zone=public --add-port=3306/tcp
    firewall-cmd --permanent --zone=public --add-port=3306/udp firewall-cmd --reload #使最新的防火墙设置规则生效
    • 创建用户并授予权限

    创建一个普通用户 sa ,密码是123456;给这个用户授予 SELECT,INSERT,UPDATE,DELETE 的远程访问的权限,这个账号一般用于提供给实施的系统访问

    CREATE USER 'sa'@'%' IDENTIFIED BY '123456';
    GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'sa'@'%';

    创建一个管理员用户 admin 账号 ,密码是 123456 ;给这个用户授予所有的远程访问的权限。这个用户主要用于管理整个数据库、备份、还原等操作

    CREATE USER 'admin'@'%' IDENTIFIED BY '123456';
    GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%';
    • 设置用户 root 的访问权限
    #可以在任意 IP 下被访问
    grant all privileges on *.* to root@"%" identified by "密码";
    #如果上述执行完并flush privileges还是不生效,可以换成以下方式
    update user set host='%' where user='root' #设置用户 root 可以在本地被访问
    grant all privileges on *.* to root@"localhost" identified by "密码";
    • 使授权立刻生效(以上授权操作最好都附加上该语句
    flush privileges;
  • 常用命令

    systemctl start mysqld  #启动mysqld
    systemctl stop mysqld #停止mysqld
    systemctl restart mysqld #重启mysqld
    systemctl enable mysqld #设置开机启动
    systemctl status mysqld #查看 MySQL Server 状态

参考

window和linux(centos7)安装mysql5.7的更多相关文章

  1. linux centos7 安装mysql-5.7.17教程(图解)

    1系统约定安装文件下载目录:/data/softwareMysql目录安装位置:/usr/local/mysql数据库保存位置:/data/mysql日志保存位置:/data/log/mysql 2下 ...

  2. Linux CentOS7 安装 Mysql5.7.19

    第二次安装会安装失败 1.先停止mysql服务  service mysql stop 2.检查是否卸载干净   find / -name mysql      多用几个命令检查,不要删到其他组件的 ...

  3. Linux CentOS7安装Mysql5.7

    一.下载mysql mkdir /home/install #创建install目录 在/home/install目录下下载mysql5.7 wget https://cdn.mysql.com//D ...

  4. Centos7 安装 MySQL5.7

    Centos7 安装 MySQL5.7 一.环境介绍 1.安装包版本介绍 MySQL 有三种安装方式:RPM安装.二进制包安装.源码包安装.我们这篇文章以二进制方式安装MySQL 软件名称 版本 系统 ...

  5. 转:Linux 编译安装 Mysql5.7

    http://broqiang.com/2017/04/18/Mysql-Install-5.7.18-Linux-Compile/ 原文 Linux 编译安装 Mysql5.7 Ubuntu 下快速 ...

  6. Linux下安装mysql5.6.11(找点有用的信息太费劲)(转)

    Linux下安装mysql5.6.11(找点有用的信息太费劲) (2013-04-25 10:25:09)     1.申请阿里云Linux服务器 昨天在阿里云申请了一个免费试用5天的Linux云服务 ...

  7. Linux CentOS7 安装 Qt 5.9.2

    Linux CentOS7 安装 Qt 5.9.2 参考链接 http://doc.qt.io/qt-5/linux.html sudo yum groupinstall "C Develo ...

  8. Linux下安装mysql5.7

    Linux下安装mysql5.7   首先准备好mysql5.7.17的安装包,安装包放在  /data/software 目录下 进入到 /usr/local 目录下,解压mysql安装包 命令: ...

  9. LINUX CentOS7安装字体库

    LINUX CentOS7安装字体库 2017年12月26日 17:06:07 q260996583 阅读数:4866更多 个人分类: linux   JAVA画图时常用到Font 类对象 这样的对象 ...

随机推荐

  1. Uva 12563 Jin Ge Jin Qu hao(01背包)

    题意: 假定你在唱KTV,还剩下t秒时间.你决定接下来唱你最喜爱的n首歌(不包含劲歌金曲)中的一些歌曲.在时间结束之前再唱一个劲歌金曲.使得唱的歌的总曲目尽量多以及时间总长度. 输入保证所有n+1曲子 ...

  2. 2017工业软件top100

  3. celery的入门使用

    一.安装步骤 二.使用方法 三.和Django结合 四.部署和监控

  4. HTTP 协议解析

    目录 目录 HTTP 协议 HTTP 协议工作原理 HTTP Request 请求行 Request Header HTTP Response 状态行 Response Header Body HTT ...

  5. Linux_自制系统服务启动脚本

    目录 目录 前言 Case语句 Apache 启动脚本 Postfix service 启停脚本 前言 在Linux的某些系统服务中,需要自己定制启动服务的脚本.通常会使用Cash语句来实现. Cas ...

  6. Vagrant 手册之 box - box 的文件格式

    原文地址 过去,box 只是 VirtualBox 导出的 tar 文件.由于 Vagrant 现在支持多个 provider 和版本控制,box 文件稍微复杂一些. 用于 Vagrant 1.0.x ...

  7. Borland C++ Builder 编译绿色Exe程序

    按照“打开Project/Option 翻到Packages页,去掉Build with runtime packages前面的勾. http://www.jinyuanbao.cn翻到Linker页 ...

  8. Altium Designer chapter6总结

    绘制PCB中需要注意的如下: (1)网络表的载入:网络表是原理图与PCB之间的桥梁,而AD实现了真正的双向同步设计.在装入网表之前需要先添加相应的封装库. (2)元件的布局:一般采用手工布局:按照模块 ...

  9. mysql行锁和死锁检测

    行锁顾名思义,就是针对单行数据加锁,在mysql中,锁的实现是由引擎层实现的,MyISAM引擎就不支持行锁 不支持行锁就意味着并发控制只能使用表锁,也就是说同一时间,在这个表上只能有一个更新在执行,这 ...

  10. 正则表达式从入门到放弃「Java」

    正则表达式能做什么? 正则表达式可以用来搜索.编辑或处理文本. 「都懂它可以处理文本,可到底是怎么回事?」 正则表达式的定义 百度百科:正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特 ...