linux mysql5.7 安装教程_Linux(Centos 7) 安装 Mysql 5.7 步骤 配置过程

一、检查是否已经安装了mysql

[root@localhost /]# rpm -qa | grep -i mysql

如果有,则使用删除语句删除

[root@localhost /]# yum -y remove mariadb-libs-5.5.56-2.el7.x86_64

再使用查询命令,查找mysql相关的文件

[root@localhost /]# find / -name mysql

然后把存在的文件都删除

[root@localhost /]# rm –rf {目录名}

二、下载mysql安装包

进入包下载所放位置下载

[root@localhost /]# cd /usr/local/src

[root@localhost src]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

进行解压

[root@localhost src]# tar zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

[root@localhost src]# ls

mysql-5.7.25-linux-glibc2.12-x86_64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

移位置并改名

[root@localhost src]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql

[root@localhost src]# cd /usr/local/mysql

[root@localhost mysql]# ls

bin COPYING docs include lib man README share support-files

三、配置初始化mysql

添加用户组和新用户名

[root@localhost mysql]# groupadd mysql

[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql

创建data目录

[root@localhost mysql]# mkdir data

修改mysql目录用户为刚刚新建的mysql组中的mysql用户

[root@localhost mysql]# chown -R mysql:mysql ./

安装必要文件包

[root@localhost mysql]# yum install -y libaio

初始化安装mysql数据库

[root@localhost mysql]#./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

2019-07-07T07:51:36.066665Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2019-07-07T07:51:37.197916Z 0 [Warning] InnoDB: New log files created, LSN=45790

2019-07-07T07:51:37.299392Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2019-07-07T07:51:37.823229Z 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: 0c916440-a08c-11e9-87be-000c2954a0d9.

2019-07-07T07:51:37.846198Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2019-07-07T07:51:37.847191Z 1 [Note] A temporary password is generated for root@localhost: yrntyj)qo6Nd

修改my.cnf配置文件,从版本5.7.18开始,mysql免安装二进制包中就不包含该文件了,即不需要my.cnf文件也可以正常运行;my.conf文件中配置的选项会在命令行启动mysql的时候作为参数进行启动,为了后面搭建mysql主从环境方便,下面可以添加了一个简单的my.cnf文件作为实例(如果只是单纯的搭建一个mysql实例,可以直接忽略此步骤),使用vim /etc/my.cnf命令,如果在该目录上不存在则会新建

[mysqld]

datadir=/data/mysql/data

socket=/tmp/mysql.sock

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/usr/local/mysql/data/mysqld.pid

四、其他配置

添加开机启动

[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld

修改mysqld,使用vim /etc/init.d/mysqld 命令 修改以下代码部分

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

设置开机启动

[root@localhost mysql]# chkconfig --add mysqld

为了可以在任意目录上都可以使用mysql命令登录mysql,将mysql安装目录配置到环境变量中,在/etc/profile文件的末尾添加以下代码

export PATH=$PATH:/usr/local/mysql/bin

使配置文件的配置立即生效

[root@localhost mysql]# source /etc/profile

重启mysql服务,并且使用mysql的root用户登录mysql

[root@localhost mysql]# service mysqld restart

Shutting down MySQL.... SUCCESS!

Starting MySQL.. SUCCESS!

[root@localhost mysql]# mysql -uroot -p

Enter password:

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

Your MySQL connection id is 2

Server version: 5.7.25 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>

修改root用户的密码为root,并且刷新

mysql> alter user 'root'@'localhost' identified by 'root';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

此时mysql数据库只能在本机上使用mysql命令进行登录,还无法使用navicat等数据库可视化工具进行远程登录,下面设置允许root用户远程连接数据库

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 user.Host='%' where user.User='root';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

查看防火墙

[root@localhost mysql]# firewall-cmd --state

running

打开3306端口

[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

防火墙重启

[root@localhost mysql]# firewall-cmd --reload

success

至此,可以直接使用navicat等连接数据库

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值