Linux安装mysql8.0(踩坑实况)

系统环境:CentOS Linux release 7.3.1611

下载mysql8.0

可以去MySQL官网下载

查看linux是32/64位

uname -a
#如果是x86_64说明是64位机

这里选择64位下载
Mysql官网
右键复制下面的连接,copy到linux
MySQL下载
利用wget下载

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

安装MySQL

tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64

解压

移动并重命名

mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql

创建mysql用户组和用户并修改权限

#创建mysql组
groupadd mysql
#创建用户mysql
useradd -r -g mysql mysql

useradd -r 创建系统用户 -g 为用户分配组

cat /etc/passwd 可见
第三段uid为996

/etc/passwd

uid 0 为root用户
uid 1~999为系统用户
uid 100~65535为普通用户

创建数据目录并赋予权限

mkdir -p  /data/mysql              #创建目录
chown mysql:mysql -R /data/mysql   #赋予权限

mkdir -p 递归创建目录,如果目录不存在也会创建
chown 用户:组 -R (递归修改) 目录

扫描二维码关注公众号,回复: 11486462 查看本文章

配置/etc/my.cnf

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
character_set_server=utf8mb4
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/data/mysql/mysql.err
#pid-file=/var/run/mariadb/mariadb.pid
pid-file=/data/mysql/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

初始化数据库

进入目录

cd /usr/local/mysql/bin/

初始化

./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

【初始化失败】./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

安装缺少的东西

yum install -y libaio-devel.x86_64

再次安装,结果如下
圈起来的为随机生成的密码,建议先保存下来

在这里插入图片描述

启动MySQL

复制服务文件

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

启动mysql

systemctl start mysql

mysql启动失败

Failed to start mysql.service: Unit not found

注:后来,发现不用安装如下的东西,只是创建一个软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin

下面画线的为我踩的坑,仅供参考
安装mariadb-server

#安装服务
yum install -y mariadb-server
#启动服务
systemctl start mariadb.service

启动mariadb-server失败
在这里插入图片描述
debug根据刚配置的日志文件/data/mysql/mysql.err
在这里插入图片描述
找到[error]项,复制百度

#进入目录
cd /data/mysql
#删除文件ib_logfile*和ibdata*
rm -f ibdata* ib_logfile*

后记:ibdata* ib_logfile* 文件很重要,若删除,可能会发生数据库数据和日志的不一致性,导致数据库无法正常使用。
请谨慎删除,删除前请做好备份。

紧接着下一个[ERROR] Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.

#根据提示,运行
mysql_upgrade

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

这里用yum安装了一个lsb_release
后来很久也没找到原因,然后systemctl start mysql
systemctl status mysql 发现报错不一样了

启动mysql失败Starting MySQL…/etc/redhat-lsb/lsb_log_message: line 3: /etc/init.d/functions: No such file or directory

yum install initscripts
重新启动mysql
service mysql restart

Starting MySQL…The server quit without updating PID file (/data/mysql/mysql.pid).[FAILED]

#自己创建一个/data/mysql/mysql.pid,里面随意输入8888
touch /data/mysql/mysql.pid
vim进去输入 8888
service mysql restart
进入/data/mysql/msyql.err查看错误

Unsupported redo log format (0). The redo log was created before MySQL 5.7.9

#删掉ib_logfile0,ib_logfile1
cd /data/mysql
rm ib_logfile0 ib_logfile1

后记:ibdata* ib_logfile* 文件很重要,若删除,可能会发生数据库数据和日志的不一致性,导致数据库无法正常使用。
请谨慎删除,删除前请做好备份。

#重新启动mysql
service mysql restart

这次终于启动成功了

登录MySQL

#登录mysql
mysql -u root -p

ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password’ cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

原因:上面用了mariadb,不支持sha256加密
解决:卸载刚刚安装的mariadb

yum remove -y mariadb
mysql -u root -p
输入刚刚截图的随机生成的密码

在这里插入图片描述
登录成功!!!

注:
vim /etc/my.cnf
在[mysqld]下面添加一行。
//可以跳过密码验证
skip-grant-tables
//可以跳过域名解析
skip-name-resolve
然后重启一下mysql
service mysql restart

修改MySQL密码

#修改root密码,%表示所有host都可以访问
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
#设置密码不过期
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
#刷新
FLUSH PRIVILEGES;

用navicat连接MySQL

在mysql下
#访问mysql库
use mysql
#使root能再任何host访问
update user set host = '%' where user = 'root';
#刷新
FLUSH PRIVILEGES;           

如上,所有过程就结束了。

安装linux部分借鉴:
https://blog.csdn.net/qq_37598011/article/details/93489404
感谢

一些其他问题

secureCRT长时间连接

在session设置中,Terminal->Send protocol NO-OP勾上。后面的时间设置为小于自动断开连接的时间。
在这里插入图片描述

secureCRT固定tab的名字

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/LittleSeedling/article/details/105851113