mysql 8.0.27安装部署和配置(RPM方式)

安装准备工作

安装依赖包:
yum -y install numactl libaio-devel.x86_64

创建文件夹并进入:
mkdir /usr/local/mysql
mkdir /usr/local/mysql/src
mkdir /usr/local/mysql/tmp
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/log
cd /usr/local/mysql/src
下载地址:
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar
解压文件:
tar -xvf mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar

解压后文件

安装

依次按顺序安装
rpm -ivh mysql-community-common-8.0.27-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.27-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.27-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-8.0.27-1.el8.x86_64.rpm

查看是否安装成功

【方式一:】
    mysql 安装成功后,会自动建立 mysql 用户、用户组。
    cat /etc/passwd | grep mysql
    cat /etc/group | grep mysql
    
【方式二:】
    mysqladmin --version

启动服务

启动:
systemctl start mysqld

报错
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.

用提示的指令查看异常日志
systemctl status mysqld.service

根据错误提示区解决问题,然后再启动服务:
systemctl start mysqld

查看初始密码:
cat /var/log/mysqld.log | grep password

登录:
mysql -u root -p

修改默认密码(注意Root.是必须要要的):
ALTER user 'root'@'localhost' IDENTIFIED BY 'Root.123456';

开放远程登录权限:
use mysql;
select host,user from user;
update user set host='%' where user ='root';
FLUSH PRIVILEGES;

登录加密规则解决办法:
ALTER USER 'root' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;#修改加密规则
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY '123456';#重新更新一下密码
FLUSH PRIVILEGES; #刷新权限

配置文件更改(非必须)

要修改mysql数据和日志存放位置等信息,配置文件是/etc/my.cnf
vi /etc/my.cnf

修改内容如下:
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/tmp/mysql.sock
lower_case_table_names=1
#必填项
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/usr/local/mysql/log/error.log
pid-file=/usr/local/mysql/data/mysql.pid

[client]
port=3306
#这里客户端也指定和mysqld一样的路径,不然客户端登录会报错
socket=/usr/local/mysql/tmp/mysql.sock
给文件授权:
chown -R mysql:mysql /usr/local/mysql

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注