使用工具及镜像:
虚拟机:VMware16
openeuler镜像:openEuler-22.03-LTS-x86_64
mysql版本:mysql-5.7.40-1.el7.x86_64.rpm-bundle
如果设置与主机同一个网段就设置桥接,其他模式也可以满足使用
下载OpenEuler镜像,这里测试用的是openEuler-22.03-LTS-x86_64,下载地址:https://repo.openeuler.org/openEuler-22.03-LTS/ISO/x86_64/openEuler-22.03-LTS-x86_64-dvd.iso
选择第一个Install openEuler 22.0.-LTS进入安装界面
# cd /etc/sysconfig/network-scripts/
# vi ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #dchp修改为static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=61edc1b6-af48-4d50-9886-c49d9af5bd7f
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.1.111 #设置为自己的IP
PREFIX=24
GATEWAY=192.168.1.1 #设置为自己的网关
NETMASSK=255.255.255.0 #子网掩码
DNS1=192.168.1.1 #DNS1
# systemctl restart NetworkManager
# yum -y install tar
# yum -y install vim
https://downloads.mysql.com/archives/community/
# yum repolist all | grep mysql
# tar -xvf mysql-5.7.40-1.el7.x86_64.rpm-bundle.tar -C /mysql/mysql
解压结果如下:
注意安装顺序
# cd /mysql/mysql
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.40-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-common-5.7.40-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.40-1.e################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.40-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-libs-5.7.40-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.40-1.el7################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.40-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-client-5.7.40-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.40-1.e################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.40-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-server-5.7.40-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.40-1.e################################# [100%]
/usr/lib/tmpfiles.d/mysql.conf:23: Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.
再执行 rpm -qa | grep mysql 命令查看安装情况:
# mysqld --initialize --console;
获取初始化的密码
# cat /var/log/mysqld.log | grep password;
一般第一次是没有启动成功
# systemctl start mysqld
这里可以三种方式排查错误信息
systemctl status mysqld查看错误信息
journalctl -xe
cat /var/log/mysqld.log (在mysql配置文件 /etc/my.cnf中配置)
# chown -R mysql:mysql /var/lib/mysql
如果不行再暴力授权到777
# chmod 777 /usr/sbin/mysqld
# chmod 777 /var/lib/mysql/*
# systemctl start mysqld
# systemctl status mysqld
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file
联网直接执行
# yum install libncurses* -y
离线处理方式#
# cp /lib64/libncurses.so.6 /lib64/libncurses.so.5
或者 添加软连接
# ln -s /lib64/libncurses.so.6 /lib64/libncurses.so.5
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
防止在远程不能登陆:alter user root identified with mysql_native_password by '123456';(执行这个再继续可能避免出现退出后不能再登录的问题,下面ERROR 1045 (28000))
mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> quit;
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES)
# vim /etc/my.cnf
在[mysqld]下添加skip-grant-tables,保存即可。
重启mysql服务
# systemctl stop mysqld
# systemctl start mysqld
# mysql -u root -p
直接回车不需要输入密码(出现Enter Password 也一样直接回车,即可登陆成功)
mysql> USE mysql;
mysql> update user set authentication_string=password('123456') where user='root';
mysql> flush privileges;
mysql> quit;
然后删除/etc/my.cnf文件中添加的skip-grant-tables,重启mysql服务
查看已经开放的端口
firewall-cmd --list-ports 或 firewall-cmd --query-port=3306/tcp
开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙使开放的端口生效:
systemctl restart firewalld.service
# mkdir /mysql/data/
# service mysqld stop
# cp -rf /var/lib/mysql /mysql/data/
# vim /etc/my.cnf
# chown -R mysql:mysql /mysql/data
修改MySQL启动脚本/etc/init.d/mysqld,执行"vim /etc/init.d/mysqld "(如果没有此文件,就不需要修改,这里就没有该文件)
cat /var/log/mysqld.log出现以下内容:
Can't create test file /mysql/data/mysql/localhost.lower-test
# vim /etc/selinux/config
修改SELINUX=disabled,然后重启服务器
# reboot
再重启mysql服务即正常。
# service mysqld restart
# service mysqld status
# cp /usr/lib/systemd/system/mysqld.service /etc/init.d/mysql
# chmod +x /etc/init.d/mysql
# vim /etc/init.d/mysql
添加下面三行(shell脚本需要保证第一行是#!/bin/bash,否则文件将不能被识别)
#!/bin/bash
#chkconfig: 2345 81 96
#description: StartMySQL
# chkconfig --add mysql
# chkconfig --list
注意看到mysql后面的345都是开或者是on表示成功, 如果显示关或者 off 则需要手动开启,执行以下命令
# chkconfig --level 345 mysqld on