centos二进制安装mysql_centos7 安装mysql5.7(二进制安装)

一、卸载默认安装的mariadb

[root@localhost ~]# yum remove mariadb* -y

二、添加mysql用户

[root@localhost ~]# useradd -s /sbin/nologin -M mysql

#-s 指定shell

#-M 不创建家目录

三、解压tar文件并移动到指定目录

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

[root@localhost~]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql

[root@localhost~]# mv mysql /usr/local/mysql

四、修改目录所属

[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/

五、初始化mysql

[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data2019-08-08T01:26:04.343294Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for moredetails).2019-08-08T01:26:04.491621Z 0 [Warning] InnoDB: New log files created, LSN=45790

2019-08-08T01:26:04.530234Z 0[Warning] InnoDB: Creating foreign key constraint system tables.2019-08-08T01:26:04.587027Z 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: 7d4db01d-b97b-11e9-8ac2-000c290afcba.2019-08-08T01:26:04.588261Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed'cannot be opened.2019-08-08T01:26:04.590350Z 1 [Note] A temporary password is generated for root@localhost: 2op_Dr?L)klu

六、创建系统服务,并修改参数

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

[root@localhost ~]#vi /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

#修改上边俩行参数,添加指定的mysql目录和数据目录

七、编辑配置文件

[root@localhost ~]# vi /etc/my.cnf

[mysqld]

user=mysql

port= 3306socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

log-error=/usr/local/mysql/data/mysql.log

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

character-set-server=utf8

collation-server=utf8_bin

八、添加环境变量

[root@localhost ~]# vi.bash_profile

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

#添加上边这行环境变量

[root@localhost ~]# source .bash_profile

九、启动mysql

[root@localhost ~]# /etc/init.d/mysqld start

Starting MySQL. SUCCESS!

十、修改mysql密码及允许远程登录

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

Enter password: #密码为初始化时,自动生成的密码

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

Your MySQL connectionid is 2Server version:5.7.25Copyright (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 clearthe current input statement.

mysql> set password=password('123456');

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

mysql>use mysql;

Reading table informationforcompletion of table and column names

You can turn off this feature to get a quicker startup with-A

Database changedmysql> selecthost,user from user;+-----------+---------------+

| host | user |

+-----------+---------------+

| localhost | mysql.session |

| localhost | mysql.sys |

| localhost | root |

+-----------+---------------+

3 rows in set (0.00sec)

mysql> update user set host='%' where user='root';

Query OK,1 row affected (0.00sec)

Rows matched:1 Changed: 1 Warnings: 0mysql>flush privileges;

Query OK,0 rows affected (0.00 sec)

十一、添加系统服务及设置自启动

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

[root@localhost~]# chkconfig --level 35 mysqld on

注:记得关闭防火墙或者添加防火墙策略

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值