前端之家收集整理的这篇文章主要介绍了
Centos 7 解压安装mysql5.7,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
之前在各大论坛上看到有很多相关介绍,但是总觉得自己安装的时候有些问题,所以这一篇借鉴
博客园-大大的橙子,但是,他的文章中安装过程中有有点问题,所以在其基础上进行了修修补补,所以目前本人经过多次裸机安装,亲测正常。
卸载系统自带的Mariadb
[root@aliyun ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@aliyun ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
删除etc目录下的my.cnf文件
[root@aliyun ~]# rm /etc/my.cnf
rm: cannot remove ?etc/my.cnf? No such file or directory
[root@aliyun ~]# rpm -qa | grep MysqL
[root@aliyun ~]#
安装必要软件
[root@aliyun ~]# yum install -y libaio
[root@aliyun ~]# cat /etc/group | grep MysqL
[root@aliyun ~]# cat /etc/passwd | grep MysqL
[root@aliyun ~]# groupadd MysqL
[root@aliyun ~]# useradd -g MysqL MysqL
制定password 为111111
[root@aliyun ~]# passwd MysqL
Changing password for user MysqL.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
由于我的/usr/local空间不足,所以我安装到/var
[root@aliyun var]# tar -zxvf MysqL-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@aliyun var]# mv MysqL-5.7.18-linux-glibc2.5-x86_64/ MysqL57
更改所属的组和用户
[root@aliyun var]# chown -R MysqL MysqL57/
[root@aliyun var]# chgrp -R MysqL MysqL57/
[root@aliyun var]# cd MysqL57/
[root@aliyun MysqL57]# mkdir data
[root@aliyun MysqL57]# chown -R MysqL:MysqL data
配置my.cnf
[MysqL]
# 设置MysqL客户端默认字符集
default-character-set=utf8
[MysqLd]
skip-name-resolve
#设置3306端口
port = 3306
# 设置MysqL的安装目录
basedir=/var/MysqL57
# 设置MysqL数据库的数据的存放目录
datadir=/var/MysqL57/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
开始初始化安装,注意里面的数据库密码,请暂时先保存下来,是初始化密码,登陆后再修改
shell> bin/MysqLd --initialize --user=MysqL --basedir=/var/MysqL57/ --datadir=/var/MysqL57/data/
2018-01-31T14:15:21.160016Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-01-31T14:15:25.102080Z 0 [Warning] InnoDB: New log files created,LSN=45790
2018-01-31T14:15:25.537811Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-01-31T14:15:25.646880Z 0 [Warning] Failed to setup SSL
2018-01-31T14:15:25.716100Z 0 [Warning] SSL error: SSL context is not usable without certificate and private key
2018-01-31T18:14:25.716295Z 1 [Warning] A temporary password is generated for root@localhost: rq/Dldw^lkdfd
[root@aliyun MysqL57]# cp ./support-files/MysqL.server /etc/init.d/MysqLd
[root@aliyun MysqL57]# chown 777 /etc/my.cnf
[root@aliyun MysqL57]# chmod +x /etc/init.d/MysqLd
[root@aliyun MysqL57]# /etc/init.d/MysqLd restart
Shutting down MysqL.. SUCCESS!
Starting MysqL. SUCCESS!
设置开机启动
[root@aliyun MysqL57]# chkconfig --level 35 MysqLd on
[root@aliyun MysqL57]# chkconfig --list MysqLd
[root@aliyun MysqL57]# chmod +x /etc/rc.d/init.d/MysqLd
[root@aliyun MysqL57]# chkconfig --add MysqLd
[root@aliyun MysqL57]# chkconfig --list MysqLd
[root@aliyun MysqL57]# service MysqLd status
SUCCESS! MysqL running (4475)
设置/etc/profile环境 在尾部添加
export PATH=$PATH:/var/MysqL57/bin
执行source 使配置文件生效
[root@aliyun MysqL57]# source /etc/profile
使用初始密码,进行连接数据库
[root@aliyun bin]# MysqL -uroot -p
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 5
Server version: 5.7.18
Copyright (c) 2000,2017,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.
#修改密码为 111111
MysqL> set PASSWORD = PASSWORD('111111');
Query OK,0 rows affected,1 warning (0.00 sec)
MysqL> flush privileges;
Query OK,0 rows affected (0.01 sec)
#添加远程访问权限
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.sys |
+-----------+-----------+
rows in set (0.00 sec)
create user 'xxx'@'%' identified by '123'; 这里 @‘%’ 表示在任何主机都可以登录
重启生效
[root@aliyun bin]# /etc/init.d/MysqLd restart
Shutting down MysqL.. SUCCESS!
Starting MysqL. SUCCESS!
设置任何目录下都可以使用MysqL命令
ln -s /var/MysqL57/bin/MysqL /usr/bin/MysqL
原文链接:/centos/374770.html