ccentos7 安装mysql5.7,centos7安装mysql5.7

一、下载mysql离线安装包tar文件

安装文件上传工具

[root@centos1--1- ~]# yum install lrzsz

[root@centos1--1- ~]# cd /usr/local/

[root@centos1--1- local]# rz #上传文件到linux

rz waiting to receive.

Starting zmodem transfer. Press Ctrl+C to cancel.

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

100% 629748 KB 12348 KB/sec 00:00:51 0 Errors

[root@centos1--1- local]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

[root@centos1--1- local]# mv mysql-5.7.25-linux-glibc2.12-x86_64/ mysql

二、创建用户和组

#添加用户组mysql

[root@centos1--1- local]# groupadd mysql

#添加mysql用户,并归属于mysql组

[root@centos1--1- local]# useradd -g mysql mysql

#给mysql用户改密码

[root@centos1--1- local]# passwd mysql

Changing password for user mysql.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

#给已有的用户增加工作组

[root@centos1--1- local]# gpasswd -a mysql mysql

Adding user mysql to group mysql

三、卸载centos7自带mariadb

#查看系统自带的mariadb

[root@centos1--1- local]# rpm -qa|grep mariadb

mariadb-libs-5.5.64-1.el7.x86_64

#卸载mariadb

[root@centos1--1- local]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64

四、检查mysql是否存在

#检查mysql是否存在,若存在 rpm -e --nodeps mysql

[root@centos1--1- local]# rpm -qa|grep mysql

[root@centos1--1- local]#

五、更改所属的组和用户

[root@centos1--1- local]# pwd #查看当前位置

/usr/local

[root@centos1--1- local]# chown -R mysql mysql

[root@centos1--1- local]# chgrp -R mysql mysql/

[root@centos1--1- local]# cd mysql/

[root@centos1--1- mysql]# mkdir data

[root@centos1--1- mysql]# chown -R mysql:mysql data

[root@centos1--1- local]# ll

drwxr-xr-x. 10 mysql mysql 141 Apr 3 00:11 mysql

六、创建my.cnf文件

[root@centos1--1- mysql]# pwd

/usr/local/mysql

[root@centos1--1- mysql]# vim my.cnf

#复制以下代码

[mysql]

socket=/var/lib/mysql/mysql.sock # set mysql client default chararter default-character-set=utf8

[mysqld]

socket=/var/lib/mysql/mysql.sock # set mysql server port port = 3306 # set mysql install base dir basedir=/usr/local/mysql # set the data store dir datadir=/usr/local/mysql/data # set the number of allow max connnection max_connections=200 # set server charactre default encoding character-set-server=utf8 # the storage engine default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M explicit_defaults_for_timestamp=true

[mysql.server]

user=mysql basedir=/usr/local/mysql

七、安装mysql

[root@centos1--1- mysql]# pwd

/usr/local/mysql

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

# 原因是缺少依赖 libnuma.so.1 通过yum安装

[root@centos1--1- mysql]# yum -y install numactl.x86_64

error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

##输出这样表示成功

2020-04-02T16:19:01.160728Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-04-02T16:19:01.346712Z 0 [Warning] InnoDB: New log files created, LSN=45790

2020-04-02T16:19:01.377032Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2020-04-02T16:19:01.433491Z 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: a9e82d4e-74fd-11ea-b824-001c42010173.

2020-04-02T16:19:01.434736Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2020-04-02T16:19:01.435331Z 1 [Note] A temporary password is generated for root@localhost: Ypx=pPA_G8Dh

Ypx=pPA_G8Dh 系统随机生成的密码,用于第一次登陆

设置文件及目录权限:

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

[root@centos1--1- mysql]# chmod 777 my.cnf

[root@centos1--1- mysql]# chmod +x /etc/init.d/mysqld

八、启动mysql

[root@centos1--1- mysql]# /etc/init.d/mysqld start

#输出如下

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

ERROR! MySQL server PID file could not be found!

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

Starting MySQL.my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

Logging to '/usr/local/mysql/data/centos1--1-.shared.err'.

SUCCESS!

九、设置开机启动

[root@centos1--1- mysql]# chkconfig --level 35 mysqld on

[root@centos1--1- mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native

systemd services. SysV configuration data might be overridden by native

systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.

To see services enabled on particular target use

'systemctl list-dependencies [target]'.

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@centos1--1- mysql]# chmod +x /etc/rc.d/init.d/mysqld

[root@centos1--1- mysql]# chkconfig --add mysqld

[root@centos1--1- mysql]# chkconfig --add mysqld

[root@centos1--1- mysql]# service mysqld status

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

SUCCESS! MySQL running (10070)

十、环境变量

[root@centos1--1- mysql]# vim /etc/profile

#在最后一行添加一下内容

#mysql

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

#使配置生效

[root@centos1--1- mysql]# source /etc/profile

十一、登陆mysql和重置密码

#-pYpx=pPA_G8Dh -p 后面是安装mysql时生成的密码

[root@centos1--1- mysql]# mysql -uroot -pYpx=pPA_G8Dh

mysql: [Warning] Using a password on the command line interface can be insecure.

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

Your MySQL connection id is 2

Server version: 5.7.25

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> set PASSWORD = PASSWORD('root'); #'root'为设置的密码

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

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

# 使用新密码登陆mysql

[root@centos1--1- mysql]# mysql -uroot -proot

mysql: [Warning] Using a password on the command line interface can be insecure.

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

Your MySQL connection id is 3

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> show databases;

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

| Database |

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

| information_schema |

| mysql |

| performance_schema |

| sys |

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

4 rows in set (0.00 sec)

mysql>

十二、添加远程访问权限

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 user = 'root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select host,user from user;

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

| host | user |

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

| % | root |

| localhost | mysql.session |

| localhost | mysql.sys |

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

3 rows in set (0.00 sec)

mysql> exit

#重启mysql生效

[root@centos1--1- mysql]# /etc/init.d/mysqld restart

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

Shutting down MySQL.. SUCCESS!

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

Starting MySQL.my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/my.cnf' is ignored.

SUCCESS!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值