centos安装mysql5.7.21_Centos7安装mysql5.7.21

本文介绍如何在CentOS系统上安装并配置MySQL 5.7,包括卸载旧版数据库、下载安装包、创建用户组、初始化数据库、设置开机启动等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、卸载系统自带的 MariaDB

[root@CentOS ~]# rpm -qa | grepmariadb

mariadb-libs-5.5.52-1.el7.x86_64

[root@CentOS~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

2、下载 mysql5.7.21 安装包

[root@CentOS local]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

3、创建 mysql 用户组和 mysql 用户

​[root@CentOS local]# useradd mysql

4、解压安装包,并将解压好的文件夹重命名为mysql

​[root@CentOS local]# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisam_ftdump

mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisamchk

mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisamlog

mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisampack

mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql

mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded

mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_config_editor

mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_embedded

mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_install_db

mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_plugin

......(略去内容).....

[root@CentOS local]#mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql

5、将 mysql 添加为系统服务

​[root@CentOS local]# cp mysql/support-files/mysql.server /etc/init.d/mysql

[root@CentOS local]# chkconfig--add mysql

6、初始化数据库

​[root@CentOS mysql]# mkdirdata

[root@CentOS mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data2018-02-24T11:03:47.265873Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for moredetails).2018-02-24T11:03:48.343129Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-02-24T11:03:48.473269Z 0[Warning] InnoDB: Creating foreign key constraint system tables.2018-02-24T11:03:48.541782Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 63b1ed0c-1952-11e8-aa97-000c29847b2d.2018-02-24T11:03:48.542867Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed'cannot be opened.2018-02-24T11:03:48.543383Z 1 [Note] A temporary password is generated for root@localhost: =u>yyVorV7g%[root@CentOS mysql]#

例如在 /usr/local/mysql 目录下创建用于保存数据的data 目录,初始化数据库后获得的临时密码为:=u>yyVorV7g%

7、启动mysql服务,使用临时密码登录mysql

​[root@CentOS mysql]# systemctl start mysql        # 使用 service mysql start 也可以

[root@CentOS mysql]#ps -ef | grepmysql

root4654 1 0 19:07 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/CentOS.pid

mysql4739 4654 4 19:07 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=CentOS.err --pid-file=/usr/local/mysql/data/CentOS.pid

root4772 3618 0 19:07 pts/0 00:00:00 grep --color=auto mysql

[root@CentOS mysql]# ./bin/mysql -u root -p

Enter password:                     # 这里输入刚获取的临时密码

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 2Server version:5.7.21Copyright (c)2000, 2018, 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 clearthe current input statement.

mysql>

8、修改登录密码

​mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');    # 将 root 登录密码修改为123456

Query OK,0 rows affected, 1 warning (0.00sec)

mysql>

9、将 mysql 服务设置为开机启动

​[root@CentOS mysql]# chkconfig mysql on

10、设置任何远程主机都可以访问数据库

​[root@CentOS bin]# ./mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 6Server version:5.7.21MySQL Community Server (GPL)

Copyright (c)2000, 2018, 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 clearthe current input statement.

mysql> grant all privileges on *.* to 'root' @'%' identified by '123456';    # 设置任何远程主机都可以访问

Query OK,0 rows affected, 1 warning (0.00sec)

mysql>flush privileges;                # 刷新权限

Query OK,0 rows affected (0.00sec)

mysql>

11、开放 3306 端口(mysql 默认端口)

​[root@CentOS bin]# firewall-cmd --zone=public --add-port=3306/tcp --permanent    # 添加 3306端口

success

[root@CentOS bin]# firewall-cmd --reload    # 重新载入

success

[root@CentOS bin]#

12、使用 Sqlyog 客户端进行测试

39e496e26f04d255a1f7c4237f1078af.pngwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==​​

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值