linux 利用yum源安装mysql5.7

前言

  • CentOS 7
  • MySQL 5.7
  • 查找mysql源 http://repo.mysql.com

步骤

  1. 添加mysql源

    shell> rpm -ivh http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
    Retrieving http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql57-community-release-el7-10 ################################# [100%]
    

    注:卸载mysql源 rpm -e --nodeps mysql57-community-release-el7-10.noarch

  2. 查看mysql源中的mysql版本

    shell> yum info mysql-community-server
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Installed Packages
    Name        : mysql-community-server
    Arch        : x86_64
    Version     : 5.7.27
    Release     : 1.el7
    Size        : 746 M
    Repo        : installed
    From repo   : mysql57-community
    Summary     : A very fast and reliable SQL database server
    URL         : http://www.mysql.com/
    License     : Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights
                : reserved. Under GPLv2 license as shown in the Description field.
    Description : The MySQL(TM) software delivers a very fast, multi-threaded,
                : multi-user, and robust SQL (Structured Query Language) database
                : server. MySQL Server is intended for mission-critical, heavy-load
                : production systems as well as for embedding into mass-deployed
                : software. MySQL is a trademark of Oracle and/or its affiliates
                :
                : The MySQL software has Dual Licensing, which means you can use the
                : MySQL software free of charge under the GNU General Public License
                : (http://www.gnu.org/licenses/). You can also purchase commercial
                : MySQL licenses from Oracle and/or its affiliates if you do not
                : wish to be bound by the terms of the GPL. See the chapter
                : "Licensing and Support" in the manual for further info.
                :
                : The MySQL web site (http://www.mysql.com/) provides the latest
                : news and information about the MySQL software.  Also please see
                : the documentation and the manual for more information.
                :
                : This package includes the MySQL server binary as well as related
                : utilities to run and administer a MySQL server.
    
  3. 安装mysql

    shell> yum install mysql-server
    
  4. 启动mysql

    shell> systemctl start mysqld
    
  5. 查看mysql是否启动

    shell> ps -ef | grep mysql
    mysql    26517     1  0 13:13 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    root     26578 25533  0 13:13 pts/1    00:00:00 grep --color=auto mysql
    

    shell> netstat -tlnp | grep mysql
    tcp6       0      0 :::3306                 :::*                    LISTEN      26517/mysqld
    
  6. 设置root账户密码
    因为mysql5.7为了安全性的考虑,在安装的时候随机生成了一个初始密码,放在/var/log/mysqld.log文件中。查询/var/log/mysqld.log文件中的初始密码。

    cat /var/log/mysqld.log | grep password
    ----------------------------------------
    2019-10-08T03:17:09.602477Z 1 [Note] A temporary password is generated for root@localhost: ,MuwPzvkf0;y
    

    初始密码为:,MuwPzvkf0;y

  7. 修改root密码为:root

    mysql -uroot -p,MuwPzvkf0;y
    mysql> set password=password('root');
    ----------------------------------------
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    

    在重新设置密码的时候,如果密码强度不够高,会提示不安全,需要重新设置。像root123456都无法设置了。

    MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格。使用了该插件会检查设置的密码是否符合当前设置的强度规则,若不满足则拒绝设置。影响的语句和函数有:create user,grant,set password,password(),old password。

    测试时为了方便,确需设置简单密码时,可以参考 mysql5.7修改root密码 进行设置。
    也可以参考:https://blog.csdn.net/u014236541/article/details/78244601和https://www.cnblogs.com/ivictor/p/5142809.html

  8. 进入mysql

    shell> mysql -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 3
    Server version: 5.7.27 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +---------------------------+
    | Tables_in_mysql           |
    +---------------------------+
    | columns_priv              |
    | db                        |
    | engine_cost               |
    | event                     |
    | func                      |
    | general_log               |
    | gtid_executed             |
    | help_category             |
    | help_keyword              |
    | help_relation             |
    | help_topic                |
    | innodb_index_stats        |
    | innodb_table_stats        |
    | ndb_binlog_index          |
    | plugin                    |
    | proc                      |
    | procs_priv                |
    | proxies_priv              |
    | server_cost               |
    | servers                   |
    | slave_master_info         |
    | slave_relay_log_info      |
    | slave_worker_info         |
    | slow_log                  |
    | tables_priv               |
    | time_zone                 |
    | time_zone_leap_second     |
    | time_zone_name            |
    | time_zone_transition      |
    | time_zone_transition_type |
    | user                      |
    +---------------------------+
    31 rows in set (0.00 sec)
    
    mysql> quit
    Bye
    
  9. 设置mysql数据编码格式为utf8。

    编辑my.cnf

    shell> vi /etc/my.cnf
    

    在my.cnf中修改内容

    [mysqld]
    character_set_server=utf8
    

    重启mysql后,登录mysql查看设置结果:

    mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
    
    +--------------------------+-----------------+
    | Variable_name            | Value           |
    +--------------------------+-----------------+
    | character_set_client     | utf8            |
    | character_set_connection | utf8            |
    | character_set_database   | utf8            |
    | character_set_filesystem | binary          |
    | character_set_results    | utf8            |
    | character_set_server     | utf8            |
    | character_set_system     | utf8            |
    | collation_connection     | utf8_general_ci |
    | collation_database       | utf8_general_ci |
    | collation_server         | utf8_general_ci |
    +--------------------------+-----------------+
    10 rows in set (0.01 sec)
    
  10. 执行mysql_secure_installation
    安装完mysql-server后,进入生产环境之前,一定要运行一次mysql_secure_installation。运行mysql_secure_installation会执行几个设置:

    • 为root用户设置密码
    • 删除匿名账号
    • 取消root用户远程登录
    • 删除test库和对test库的访问权限
    • 刷新授权表使修改生效

    参考:MySQL----mysql_secure_installation 安全配置向导
    匿名账户参考:https://www.cnblogs.com/wzzkaifa/p/7000808.html

其它

启动mysql:systemctl start mysqld
停止mysql:systemctl stop mysqld
重启mysql:systemctl restart mysqld
查看mysql状态:systemctl status mysqld

mysql服务开启:systemctl enable mysqld
mysql服务关闭:systemctl disable mysqld
查看mysql服务是否开启:systemctl list-unit-files|grep mysqld

查看mysql版本:mysql -V
my.cnf配置文件读取顺序:mysqld --help --verbose 2> /dev/null | grep -A1 ‘Default options’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值