Linux centOS安装Mysql5.7步骤

参考自:https://www.cnblogs.com/zero-vic/p/13296857.html

  1. 下载mysql yum包:
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
  1. 安装mysql
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
  1. 安装mysql server端
yum install -y mysql-community-server

结果:

[root@VM-8-15-centos ~]# yum install -y mysql-community-server
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Determining fastest mirrors
epel                                                                                                                                     | 4.7 kB  00:00:00
extras                                                                                                                                   | 2.9 kB  00:00:00
mysql57-community                                                                                                                        | 2.6 kB  00:00:00
os                                                                                                                                       | 3.6 kB  00:00:00
updates                                                                                                                                  | 2.9 kB  00:00:00
(1/8): epel/7/x86_64/group_gz                                                                                                            |  95 kB  00:00:00
(2/8): epel/7/x86_64/updateinfo                                                                                                          | 1.0 MB  00:00:00
(3/8): extras/7/x86_64/primary_db                                                                                                        | 224 kB  00:00:00
(4/8): os/7/x86_64/group_gz                                                                                                              | 153 kB  00:00:00
(5/8): os/7/x86_64/primary_db                                                                                                            | 6.1 MB  00:00:00
(6/8): epel/7/x86_64/primary_db                                                                                                          | 6.9 MB  00:00:01
(7/8): updates/7/x86_64/primary_db                                                                                                       | 5.6 MB  00:00:01
(8/8): mysql57-community/x86_64/primary_db                                                                                               | 258 kB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.33-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.33-1.el7 for package: mysql-community-server-5.7.33-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.33-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.33-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.33-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.33-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.33-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================================================
Package                                       Arch                          Version                             Repository                                Size
==============================================================================================================================================================
Installing:
mysql-community-server                        x86_64                        5.7.33-1.el7                        mysql57-community                        173 M
Installing for dependencies:
mysql-community-client                        x86_64                        5.7.33-1.el7                        mysql57-community                         25 M
mysql-community-common                        x86_64                        5.7.33-1.el7                        mysql57-community                        308 k
mysql-community-libs                          x86_64                        5.7.33-1.el7                        mysql57-community                        2.3 M
Transaction Summary
===================
Install  1 Package (+3 Dependent packages)
Total download size: 201 M
Installed size: 876 M
Downloading packages:
(1/4): mysql-community-common-5.7.33-1.el7.x86_64.rpm                                                                                    | 308 kB  00:00:02
(2/4): mysql-community-libs-5.7.33-1.el7.x86_64.rpm                                                                                      | 2.3 MB  00:00:01
(3/4): mysql-community-client-5.7.33-1.el7.x86_64.rpm                                                                                    |  25 MB  00:00:14
(4/4): mysql-community-server-5.7.33-1.el7.x86_64.rpm                                                                                    | 173 MB  00:01:04
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                           3.0 MB/s | 201 MB  00:01:08
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.7.33-1.el7.x86_64                                                                                                   1/4
Installing : mysql-community-libs-5.7.33-1.el7.x86_64                                                                                                     2/4
/sbin/ldconfig: Renaming of /etc/ld.so.cache~ to /etc/ld.so.cache failed: Operation not permitted
warning: %post(mysql-community-libs-5.7.33-1.el7.x86_64) scriptlet failed, exit status 1
Non-fatal POSTIN scriptlet failure in rpm package mysql-community-libs-5.7.33-1.el7.x86_64
Installing : mysql-community-client-5.7.33-1.el7.x86_64                                                                                                   3/4
Installing : mysql-community-server-5.7.33-1.el7.x86_64                                                                                                   4/4
Verifying  : mysql-community-libs-5.7.33-1.el7.x86_64                                                                                                     1/4
Verifying  : mysql-community-common-5.7.33-1.el7.x86_64                                                                                                   2/4
Verifying  : mysql-community-client-5.7.33-1.el7.x86_64                                                                                                   3/4
Verifying  : mysql-community-server-5.7.33-1.el7.x86_64                                                                                                   4/4
Installed:
mysql-community-server.x86_64 0:5.7.33-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.33-1.el7         mysql-community-common.x86_64 0:5.7.33-1.el7         mysql-community-libs.x86_64 0:5.7.33-1.el7
Complete!
  1. 启动mysql服务:
systemctl start mysqld
  1. 查看mysql状态:
[root@VM-8-15-centos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-02-19 18:04:27 CST; 2min 16s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 13924 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 13864 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 13927 (mysqld)
Tasks: 28
Memory: 262.1M
CGroup: /system.slice/mysqld.service
└─13927 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Feb 19 18:04:08 VM-8-15-centos systemd[1]: Starting MySQL Server...
Feb 19 18:04:27 VM-8-15-centos systemd[1]: Started MySQL Server.
  1. 获取root用户临时密码
grep 'temporary password' /var/log/mysqld.log

结果:

[root@VM-8-15-centos ~]# grep 'temporary password' /var/log/mysqld.log
2021-02-19T10:04:19.881027Z 1 [Note] A temporary password is generated for root@localhost: bcQXw#Rhe3v)
  1. 登录mysql,修改密码
mysql -u root -p
  1. 修改密码
  • 修改密码规则
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
  • 设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
  1. 开启远程连接权限
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> update user set Host = '%' where Host = 'localhost' and User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

大功告成啦!

备注(卸载mysql)

安装mysql8.0失败后坑可能会用到的一些命令:javamakefile

删除mysql rpm

rpm -qa|grep mysql

rpm -e mysql

yum clean all


标题: Linux centOS安装Mysql5.7步骤
文章作者: lonuslan
文章链接: https://www.lonuslan.com/articles/2021/02/19/1613735500106.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Hi I'm LonusLan
    评论
    1 评论
    马内 2021-08-01 09:29

    暑期快乐,感谢博主的分享,支持了。

    技术文章,学习了。

avatar

取消