Centos rpm方式安装mysql5.7 详细

    科技2022-07-10  122

    文章目录

    1.下载mysql5.7的rpm安装包2.上传mysql安装包到centos的目录下3.安装依赖4.安装mysql5.7

    1.下载mysql5.7的rpm安装包

    https://downloads.mysql.com/archives/community/ 只需下载最新版图示4个包就可以了

    2.上传mysql安装包到centos的目录下

    [root@cm1 mysql]# ll 总用量 205864 -rw-r--r--. 1 root root 26452496 10月 2 2020 mysql-community-client-5.7.30-1.el7.x86_64.rpm -rw-r--r--. 1 root root 318688 10月 2 2020 mysql-community-common-5.7.30-1.el7.x86_64.rpm -rw-r--r--. 1 root root 2459484 10月 2 2020 mysql-community-libs-5.7.30-1.el7.x86_64.rpm -rw-r--r--. 1 root root 181564660 10月 2 2020 mysql-community-server-5.7.30-1.el7.x86_64.rpm

    3.安装依赖

    3.1 查看linux上是否已经安装了mysql,有则卸载。

    一般centos7默认安装了mariadb,这里把它卸载。

    查看:[root@cm1 bin]# rpm -qa|grep mariadb 卸载:[root@cm1 bin]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 3.2 安装mysql5.7所需要的依赖 [root@cm1 ]# yum install libaio [root@cm1 ]# yum install perl [root@cm1 ]# yum install net-tools

    4.安装mysql5.7

    4.1 分别安装mysql5.7安装包 [root@cm1 ]# rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm [root@cm1 ]# rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm [root@cm1 ]# rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm [root@cm1 ]# rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm 4.2 查看mysql5.7的状态,没有启动则把mysql启动 [root@cm1 mysql]# systemctl status mysqld #或者service mysqld status ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html

    启动mysql, active(running)代表启动成功

    [root@cm1 mysql]# systemctl start mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2020-10-01 01:19:18 CST; 1min 10s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 36299 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 36245 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 36303 (mysqld) CGroup: /system.slice/mysqld.service └─36303 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 4.3 修改密码 查看临时密码: [root@cm1 mysql]# grep password /var/log/mysqld.log 2020-09-30T17:19:14.938108Z 1 [Note] A temporary password is generated for root@localhost: EC5?kvs)Es14

    用临时密码登录mysql

    [root@cm1 mysql]# mysql -uroot -p'EC5?kvs)Es14' mysql>

    修改密码校验等级,如无必要,请跳过此步骤:

    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> set password = password("123456"); 4.4 开启远程连接,允许远程连接数据库 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 4.5 配置mysql的配置文件my.cnf(如无必要,请跳过此步骤) 打开配置文件my.cnf [root@cm1 ]# vi /etc/my.cnf

    在[mysqld]下面配置几行

    lower_case_table_names=1 #配置表名不区分大小写 1:不区分大小写 0:区分大小写 这行必须配置 默认表名是区分大小写的,不利于开发 character-set-server=utf8 #设置为默认编码为utf8 init_connect='SET NAMES utf8' max_connections=1024 #设置最大连接数

    重启mysql 重启配置才能生效

    [root@cm1 ]# systemctl restart mysqld

    至此,安装完成。

    Processed: 0.064, SQL: 8