linux安装mysql(没测过)

Linux上安装软件常见的几种方式:

源码编译
压缩包解压(一般为tar.gz)
编译好的安装包(RPM、DPKG等)
在线安装(YUM、APT等)

使用yum进行安装

1.查看是否已经安装了mysql

[root@localhost ~]# rpm -qa|grep mysql #无输出说明没有安装

2.打开网址:https://dev.mysql.com/downloads/repo/yum/
找到对应linux的版本进行下载
查看自己的版本:

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

3.复制下载文件的全名:mysql80-community-release-el7-3.noarch.rpm
下载和安装mysql源

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

4.安装MySQL源

[root@localhost ~]# sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

5.检查是否安装成功

检查是否安装成功:
执行成功后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo及 mysql-community-source.repo

linux安装mysql(没测过)_第1张图片
6.查看mysql相关资源

yum repolist enabled | grep "mysql.*-community.*"

linux安装mysql(没测过)_第2张图片
7.选择mysql版本

使用命令:yum repolist all | grep mysql,查看当前yum repolist的所有版本

8.切换版本
在这里插入图片描述9.安装mysql

在这里插入图片描述该命令会安装MySQL服务器 (mysql-community-server) 及其所需的依赖、相关组件,包括mysql-community-client、mysql-community-common、mysql-community-libs等。安装时间会比较长

10.启动

[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
停止
[root@localhost ~]# systemctl stop mysqld.service
重启
[root@localhost ~]# systemctl restart mysqld.service

修改密码

初始密码
MySQL第一次启动后会创建超级管理员账号root@localhost,初始密码存储在日志文件中:

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2020-12-06T07:32:41.399112Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Nd<-p!Fxt6A8

修改默认密码

# 先进行登录
[root@localhost ~]# mysql -uroot -p
Enter password: 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 
#密码太弱

解决方法如下:

使用复杂密码,MySQL默认的密码策略是要包含数字、字母及特殊字符;
如果只是测试用,不想用那么复杂的密码,可以修改默认策略,即validate_password_policy(以及validate_password_length等相关参数),使其支持简单密码的设定,具体方法可以参考:设置密码策略;
修改配置文件/etc/my.cnf,添加validate_password=OFF,保存并重启MySQL
修改报错后重启报错解决可参考:https://blog.csdn.net/aiyowei1106/article/details/88703746

设置编码

查看编码

mysql> SHOW VARIABLES LIKE 'character%';

设置编码
编辑/etc/my.cnf,[mysqld]节点增加以下代码

[mysqld]
character_set_server=utf8
init-connect='SET NAMES utf8'

设置开机启动

[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload

关闭防火墙
允许远程登录

	# firewall防火墙
	systemctl status firewalld
	# 查看转态
	firewall-cmd --state
	# 开启
	service firewalld start
	# 重启
	service firewalld restart
	# 关闭
	service firewalld stop
	#注意分清楚linux的版本 命令会有所不同
	#查看防火墙规则
	firewall-cmd --list-all 

删除mysql

1.检查mariadb

[root@localhost ~]# rpm -qa|grep mariadb

2.删除mariadb

[root@localhost ~]# rpm -e --nodeps mariadb-server
[root@localhost ~]# rpm -e --nodeps mariadb
[root@localhost ~]# rpm -e --nodeps mariadb-libs

3.检查mysql

[root@localhost ~]# rpm -qa|grep mysql
mysql-community-client-8.0.22-1.el7.x86_64
mysql-community-common-8.0.22-1.el7.x86_64
mysql-community-client-plugins-8.0.22-1.el7.x86_64
mysql-community-libs-compat-8.0.22-1.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-libs-8.0.22-1.el7.x86_64
mysql-community-server-8.0.22-1.el7.x86_64
[root@localhost ~]# 

4.删除mysql

[root@localhost ~]# rpm -e --nodeps xxx

linux安装mysql(没测过)_第3张图片

使用tar.xz安装

1.删除旧的,操作如上
2.下载mysql对应安装包
官网下载:历史版本下载
或者直接在虚拟机下载

[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.15-linux-glibc2.12-i686.tar

3.安装和配置

[root@localhost ~]# yum install libaio

4.创建mysql用户

[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql

5.解压并创建链接

[root@localhost mysql]# tar zxvf /root/mysql/mysql-8.0.15-linux-glibc2.12-i686.tar.gz
或者
[root@localhost mysql]# tar -xvf /root/mysql/mysql-8.0.15-linux-glibc2.12-i686.tar
或者
[root@localhost mysql]# tar -xvJf /root/mysql/mysql-8.0.15-linux-glibc2.12-i686.tar.xz
修改文件名
[root@localhost mysql]# mv mysql-8.0.15-linux-glibc2.12-i686 mysql 
将文件移动到/usr/local/
[root@localhost mysql]# cp mysql-8.0.15-linux-glibc2.12-i686.tar.xz /usr/local/

6.修改/usr/local/mysql 目录为mysql用户
cd /usr/local/mysql //进入/usr/local/mysql 目录

[root@localhost mysql]# cd /usr/local/mysql //进入/usr/local/mysql 目录
[root@localhost mysql]# chown -R mysql:mysql ./

7.mysql操作初始化

[root@localhost mysql]# ./bin/mysqld  --initialize  --user=mysql  --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data
./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 初始化报错,请执行以下命令,查看是否安装齐全
yum search libaio
yum install libaio
yum -y install numactl
yum install libnuma
yum install ld-linux.so.2
yum install libaio.so.1
yum install libnuma.so.1
yum install libstdc++.so.6
yum install libtinfo.so.5

8.启动服务

[root@localhost mysql]# cd support-files
[root@localhost support-files]# ./mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
.. SUCCESS! 

9.配置mysql环境

export MYSQL_HOME=/usr/local/mysql
export MYSQL_PATH=${MYSQL_HOME}/bin:${MYSQL_HOME}/lib
export PATH=$PATH:/usr/local/mysql/bin

linux安装mysql(没测过)_第4张图片
10.系统配置

cp /usr/local/mysql/support-files/mysql.server   /etc/init.d/mysql   //拷贝mysql.server 
chmod +x  /etc/init.d/mysql           //添加可执行权限。
chkconfig  --add mysql               // 注册启动服务
chkconfig  --list   //查看是否添加成功

linux安装mysql(没测过)_第5张图片
11.修改初始密码

[root@localhost ~]# mysql -uroot -p
Enter password:        //这里输入刚刚初始化操作时的初始密码

mysql> alter user 'root'@'localhost' identified by '你的新密码';
Query OK, 0 rows affected (0.02 sec)
#设置允许远程登录
mysql> update user set user.Host='%' where user.User='root';

12.关闭防火墙

	# firewall防火墙
	systemctl status firewalld
	# 查看转态
	firewall-cmd --state
	# 开启
	service firewalld start
	# 重启
	service firewalld restart
	# 关闭
	service firewalld stop
	#注意分清楚linux的版本 命令会有所不同
	#查看防火墙规则
	firewall-cmd --list-all 

测试

远程连接
linux安装mysql(没测过)_第6张图片
原因

mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password

解决方案

#更改加密方式
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVEER;
Query OK, 0 rows affected (0.01 sec)
#更新用户密码
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

转载链接:https://blog.csdn.net/qq_41510551/article/details/110731610

你可能感兴趣的:(linux,mysql,centos)