Centos7安装配置MySQL5.7
一:安装前准备:
1.1检查linux版本:cat /etc/system-release
CentOS Linux release 7.6.1810 (Core)
1.2查看系统是否安装MySQL:
rpm -qa | grep mysql
如果有安装则删除:
rpm -e --nodeps softfullname
1.3删除mariadb:
rpm -qa | grep mariadb
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64
报错:
错误:依赖检测失败:
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-7.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-7.el7.x86_64 需要
不检测依赖强制删除:
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
1.4关闭selinux:
getenforce
如果输出为:Enforcing
则需要关闭:
临时关闭selinux:
setenforce 0
永久关闭selinux:
vim /etc/selinux/config
SELINUX=disabled
reboot后生效
1.5检查是否安装libaio:
rpm -qa | grep libaio
yum search libaio
yum -y install libaio
二:官网下载:
2.1下载安装包:
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
选择版本
Linux - Generic
Linux - Generic (glibc2.5)(x86,64-bit)
Compressed TAR Archive
2.2上传文件到centos7
解压文件:
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
移动文件到路径:
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
建议用此命令移动:
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
cp -r mysql /usr/local/
三:安装mysql
3.1建立组和用户:
groupadd mysql
useradd -r -g mysql mysql
给mysql数据库创建专有用户,该用户只能访问mysql目录,不能访问系统其它目录
另外不建议直接用root初始化mysql,否则连接mysql时会报错:[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
3.2创建data:
cd /usr/local/mysql/
mkdir data
cd /usr/local/
chown -R mysql:mysql mysql/
3.3初始化mysql:
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
2019-01-15T01:21:28.631674Z 1 [Note] A temporary password is generated for root@localhost: uMQO;syZJ9q=
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-01-15T05:31:44.610567Z 1 [Note] A temporary password is generated for root@localhost: SXrGkn=;e1-d
记住临时密码
如果忘记密码或者想重新初始化,可以先将mysql/data目录中文件删除,然后再执行初始化命令
3.4修改配置文件:
vim /etc/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
#skip-name-resolve
#设置3306端口
port = 3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#lower_case_table_name=1
max_allowed_packet=16M
四:配置mysql:
4.1设置开机启动:
复制脚本到资源目录: cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
增加 mysqld 服务控制脚本执行权限: chmod +x /etc/rc.d/init.d/mysqld
将 mysqld 服务加入到系统服务: chkconfig --add mysqld
检查mysqld服务是否已经生效: chkconfig --list mysqld
命令输出类似下面的结果:
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用 service 命令控制 mysql 的启动和停止。
查看启动项:chkconfig --list | grep -i mysql
删除启动项:chkconfig --del mysql
启动 mysqld:service mysqld start
报错处理:
如报错:mysqld[3559]: /etc/rc.d/init.d/mysqld:行239: my_print_defaults: 未找到命令
拷贝文件到 /usr/bin
cp /usr/local/mysql/bin/my_print_defaults /usr/bin
如报错:mysqld[3683]: /etc/rc.d/init.d/mysqld: 第 259 行:cd: /user/local/mysql: 没有那个文件或目录
mysqld[3683]: Starting MySQL ERROR! Couldn't find MySQL server (/user/local/mysql/bin/mysqld_safe)
vim /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
mysqld_pid_file_path=/data/mysql
4.2添加环境变量:
vim /etc/profile
添加:
export PATH=$PATH:/usr/local/mysql/bin
export PATH
执行,使其生效:
source /etc/profile
查看是否生效:
echo $PATH
或者添加软连接 ln -s /usr/local/mysql/bin/mysql /usr/bin
五:登陆MySQL:
mysql -uroot -p
修改密码:
SET PASSWORD = PASSWORD("xxxx");
如登陆报错:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
建立软连接:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
删除软连接
rm -rf mysql.sock
不可写成,会删除链接文件
rm -rf mysql.sock/
六:添加防火墙策略:
感谢:
https://blog.csdn.net/vipbupafeng/article/details/80271089
https://www.cnblogs.com/zero-gg/p/8875598.html
https://blog.csdn.net/z13615480737/article/details/80019881
Centos7安装配置MySQL5.7的更多相关文章
- Centos7 安装配置mysql5.6
Centos7下完美安装并配置mysql5.6 Centos7将默认数据库mysql替换成了Mariadb,对于我们这些还想用mysql的人来说并不是一个好消息. 最近我搜罗了网上各种安装教程,各 ...
- centos7安装配置mysql5.6
1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. 安装mysql-co ...
- Centos7安装配置gitlab
Centos7安装配置gitlab 这篇文字我会介绍在Centos7上安装gitlab,配置gitlab的smtp,并且创建项目demo. sudo yum install openssh-serve ...
- windows下如何安装配置mysql-5.7-m14-winx64(zip格式的安装)
win7 64位下如何安装配置mysql-5.7.4-m14-winx64 1. mysql-5.7.4-m14-winx64.zip下载 官方网站下载地址:http://dev.mysql.co ...
- win7 64位下如何安装配置mysql-5.7.4-m14-winx64
win7 64位下如何安装配置mysql-5.7.4-m14-winx641. mysql-5.7.4-m14-winx64.zip下载 官方网站下载地址:http://dev.mysql.com/g ...
- Centos7安装配置Apache+PHP+Mysql+phpmyadmin
转载自: Centos7安装配置Apache+PHP+Mysql+phpmyadmin 一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl ...
- Centos7安装配置JDK8
Centos7安装配置JDK8 一.准备工作 第一步,去甲骨文官网下载Jdk相应的版本,我这里下载的是jdk1.8. 第二步将你从官网上下载下来的jdk使用FTP工具上传到云服务器上的相应目录,我的是 ...
- centos7命令行和图形界面的相互切换(附centos7安装配置教程)
一.最近安装了centos7,发现在命令行和图形界面的相互切换命令上,与centos以往版本有很大不同,先整理如下,加深记忆. 1,centos7默认安装后,跟其他版本一样,启动默认进入图形界面: 2 ...
- (转)Centos7安装配置NFS服务和挂载
Centos7安装配置NFS服务和挂载 原文:https://www.u22e.com/601.html NFS简介 NFS(Network File System)即网络文件系统,是FreeBSD支 ...
随机推荐
- Django使用admin管理后台管理数据库表
1.在admin.py文件中注册需要创建的表,例: from .models import * # Register your models here. admin.site.register(Use ...
- Lab 1-3
Lab 1-3 Analyze the file Lab01-03.exe. Questions and Short Answers Upload the Lab01-03.exe file to h ...
- c++-pimer-plus-6th-chapter06
Chapter Review 1 Both version give the same answers, but the if else version is more efficient. Cons ...
- html标签积累
<marquee>滚动标签 <marquee>标签,它是成对出现的标签,首标签<marquee>和尾标签</marquee>之间的内容就是滚动内容.&l ...
- [Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.
待解决 [Fiddler] ReadResponse() failed: The server did not return a complete response for this request. ...
- 关于Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.的解决方案
Warning: setState(...): Can only update a mounted or mounting component. This usually means you call ...
- mysql索引注意事项
mysql使用索引的注意事项 1.索引不会包含有NULL值的列 只要列中包含有NULL值都将不会被包含在索引中,复合索引中只要有一列含有NULL值,那么这一列对于此复合索引就是无效的.所以我们在数据库 ...
- PAT 1035 Password
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- iperf测试工具
一.iperf工具安装: 1.获取iperf源码安装包(iperf-3.0.5.tar.gz) 2.将iperf安装包上传到服务器/tmp/目录并解压 [root@localhost /]#cd /t ...
- 小程序BindTap快速连续点击页面跳转多次
原因: 手机端点击Tap基础事件解决300ms延迟 解决办法: success 里面加一个延迟300ms能解决 setTimeout goRob(e) { const that = this retu ...