linux 安装Mysql

一、硬件环境要求

CPU(推荐1C+)

内存(推荐2G+)

硬盘(推荐40GB+)

 

二、查看版本,并卸载历史版本

1、查看已有版本:rpm -qa|grep -i mysql
2、卸载:yum -y remove mysql-libs-5.1.73-7.el6.x86_64 (或者:rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 删除不检查依赖)

 

三、下载与安装

1、搜索mysql yum repository,获取下载地址。
2、wget https://repo.mysql.com//mysql80-community-release-el7-4.noarch.rpm
3、rpm -ivh mysql80-community-release-el7-4.noarch.rpm
4、yum install mysql-community-server -y

 

// 设置不区分大小写,必须启动前设置!!

//配置文件设置
vi /etc/my.cnf
lower_case_table_names=1

//配置生效
sudo mysqld --initialize --console

//操作授权
chown -R mysql:mysql /var/lib/mysql/

 

四、启动

1、启动mysql

service mysqld start     //查看状态:service mysqld status

2、设置开机启动

systemctl enable jenkins.service  // 开机启动(默认)
systemctl disable mysqld.service  // 开机不启动

 

五、修改密码

1、登录mysql root账户

// 查看初始随机密码
grep "password" /var/log/mysqld.log

// 登录
>mysql -u root -p

 2、修改密码

  mysql 5.7 密修改方式

set global validate_password_policy=0;set global validate_password_length=0;
alter user user() identified by 'Root@123';
flush privileges;

  mysql 8.0 密码修改方式

alter user user() identified by 'Root@123';
// INSTALL COMPONENT 'file://component_validate_password';
set global validate_password.policy=0;
set global validate_password.length=1;
flush privileges;

 3、查看密码策略:

show variables like 'validate_password%';  // 注意:mysql 8.0必须先修改密码,才能执行本语句

 

六、设置linux系统时间与centos系统保持一致

// centos系统时间设置,参考 Centos 7 系统安装与配置文档中的 #设置系统时间#

// 在mysql命令行中执行
show variables like '%time_zone%';
set time_zone=SYSTEM;
set global time_zone='+8:00';
flush privileges;

// 重启mysql

 

七、设置远程链接

  mysql 5.7 远程连接设置方式
# mysql_secure_installation
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
flush privileges;

  mysql 8.0 远程连接设置方式

create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;
flush privileges;

//  注意:完成五、六步设置后本地root账户登录密码为Root@123远程root账户登录密码为123456

 

八、创建数据和用户

create database testdb; // 删除:drop database testdb;
create user'test'@'%' identified by '123456'; // 删除:drop user 'test'@'%';
grant all privileges on testdb.* to 'test'@'%';
flush privileges;

 

九、报错和问题

1、官方KEY更新问题

  报错:

The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.

Failing package is: mysql-community-libs-compat-8.0.29-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

  解决:

更新:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 文件中KEY的内容

2022官方KEY地址:https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

 

posted @ 2021-12-20 23:18  vv_online  阅读(64)  评论(0编辑  收藏  举报