转载 https://blog.csdn.net/yejiyueshang/article/details/78745664
Linux版本:CentOS 6.5 64位
1.下载MySQL
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar
2.解压
mkdir mysql
cd mysql
[root@localhost mysql]# tar -xvf mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.20-1.el6.x86_64.rpm
mysql-community-common-5.7.20-1.el6.x86_64.rpm
mysql-community-client-5.7.20-1.el6.x86_64.rpm
mysql-community-test-5.7.20-1.el6.x86_64.rpm
mysql-community-server-5.7.20-1.el6.x86_64.rpm
mysql-community-devel-5.7.20-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.20-1.el6.x86_64.rpm
mysql-community-libs-5.7.20-1.el6.x86_64.rpm
mysql-community-embedded-5.7.20-1.el6.x86_64.rpm
3.创建MySQL用户组及用户
groupadd mysql
useradd -r -g mysql mysql
4.修改当前目录拥有者为mysql用户
chown -R mysql:mysql ./
5.删除原有MySQL
#查看已安装的软件包
yum list installed mysql*
#删除所有已安装的相关软件
yum remove mysql.x86_64 mysql-devel.x86_64 mysql-libs.x86_64 mysql-server.x86_64
6.依次安装MySQL
rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm --nosignature
rpm -ivh mysql-community-libs-5.7.20-1.el6.x86_64.rpm --nosignature
rpm -ivh mysql-community-client-5.7.20-1.el6.x86_64.rpm --nosignature
rpm -ivh mysql-community-server-5.7.20-1.el6.x86_64.rpm --nosignature
此步可能报错,信息如下:
error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-5.7.20-1.el6.x86_64
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64
perl(File::Path) is needed by mysql-community-server-5.7.20-1.el6.x86_64
perl(Getopt::Long) is needed by mysql-community-server-5.7.20-1.el6.x86_64
perl(POSIX) is needed by mysql-community-server-5.7.20-1.el6.x86_64
perl(strict) is needed by mysql-community-server-5.7.20-1.el6.x86_64
此为依赖缺失,安装即可
yum install perl
yum install libnuma*
如 libnuma* 无法安装,出现如下信息
[root@local mysql]# yum install libnuma*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.163.com
* updates: mirrors.cn99.com
Setting up Install Process
No package libnuma* available.
Error: Nothing to do
可改为安装 numactl
yum install numactl
7.启动MySQL服务
service mysqld start
8.设置MySQL用户和密码
#关闭MySQL服务
service mysqld stop
#安全模式启动MySQL
mysqld_safe --skip-grant-tables &
#登陆MySQL,此时密码随意
mysql -u root -p
#更改密码
update mysql.user
set authentication_string=password('root')
where user='root';
#刷新权限
flush privileges;
#退出MySQL
exit;
#重启MySQL
service mysqld restart
#登陆MySQL,创建用户并授权
create database gogs
create user git@localhost identified by 'git';
grant all privileges on gogs.* to git@localhost;
9.安装配置过程中遇到的问题
问题:安装mysql-community-server报错
提示信息:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.20-1.el6.x86_64
mysql-community-client(x86-64) >= 5.7.9 is needed by mysql-community-server-5.7.20-1.el6.x86_64
mysql-community-common(x86-64) = 5.7.20-1.el6 is needed by mysql-community-server-5.7.20-1.el6.x86_64
原因:
依赖的软件包未安装
yum install libnuma*
顺序安装mysql-community-common,mysql-community-libs,mysql-community-client
问题:
MySQL初始化失败
提示信息:
初始化 MySQL 数据库: [失败]
原因:
原有MySQL未完全卸载
问题:
登陆MySQL后无论运行什么都报相同错误信息
提示信息:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
原因:
安全模式修改密码后需要在MySQL中再次修改一次后退出再登陆才能正常使用
set password=password('密码');
alter user 'root'@'localhost' password expire never;
flush privileges;
exit;