目录
随机密码是:Ku;o1-i:Y5Z&,一般是12位字符,注意保存。
(一)将服务文件拷贝到init.d下,并重命名为mysqld
一、准备工作:获取安装包和相应工具
(一)所需安装包

1.FileZilla负责将文件传到服务器上。
2.Xshell负责远程连接服务器。
(二)安装包下载链接
1.懒人版直接点击下来链接下载包含三个压缩包在内的文件。
2.官方下载地址。
Mysql的下载步骤:
①
②

③往下滑

(三)在服务器上创建文件夹并上传安装包
1.在/usr/local目录下创建mysql文件夹。
python
cd /usr/local/ #进入/usr/local/目录
mkdir mysql #创建Mysql目录
mkdir mysql/mysqldb #创建数据库

2.使用FileZilla软件将Mysql安装包上传至Linux服务器的/usr/local/mysql目录下。

3.在Xshell中查看。

二、安装MySql
(一)删除系统自带的mariadb
python
rmp -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

(二)安装MySQL依赖包libaio
python
yum install libaio

(三)创建MySQL组和用户并设置密码
useradd mysql
passwd mysql

(四)将MySQL目录的权限授给MySQL用户和组
python
chown -R mysql:mysql /usr/local/mysql

(五)解压MySQL压缩包
python
cd /usr/local/mysql/
tar -zxvf mysql-8.0.28-el7-x86_64.tar.gz


(六)移动Mysql安装文件
python
mv mysql-8.0.28-el7-x86_64/* /usr/local/mysql

(七)给MySQL目录授权
python
chmod -R 777 /usr/local/mysql
chmod -R 777 /usr/local/mysql/mysqldb

(八)配置安装参数
python
vim /etc/my.cnf

提前复制下列这段内容,按下i键进入编辑模式,将内容复制到打开的my.cnf文件中:
python
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用"mysql_native_password"插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

按下ESC键,并输入:wq!保存。

在执行vim /etc/my.cnf进入检查,看到#开头的中文变成蓝色即可确认已经生效。

(九)进入MySQL安装目录的bin目录下
cd /usr/local/mysql/bin
(十)执行命令,并记住随机密码
python
./mysqld --initialize --console

随机密码是:Ku;o1-i:Y5Z&,一般是12位字符,注意保存。
(十一)启动MySQL服务-失败
python
cd /usr/local/mysql/support-files #进入support-files
./mysql.server start #启动mysql服务

(十二)进行授权
python
chmod -R 777 /usr/local/mysql
chmod -R 777 /usr/local//mysql/mysqldb

(十三)继续启动-成功
python
./mysql.server start #启动mysql服务

(十四)将MySQL加入系统进程中并重启
python
cp mysql.server /etc/init.d/mysqld
service mysqld restart # 然后重启MySQL服务

(十五)创建软链接
python
ln -s /usr/local/mysql/bin/mysql /usr/bin

至此,Mysql安装完毕!
三、修改Mysql密码
(一)启动MySQL程序
python
mysql -uroot -p

(二)修改密码
python
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

(三)设置允许远程登录
python
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;

(四)退出并重启MySQL程序
python
quit;
service mysqld restart

四、设置Mysql开机自启
(一)将服务文件拷贝到init.d下,并重命名为mysqld
python
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

(二)赋予可执行权限
python
chmod +x /etc/init.d/mysqld

(三)添加服务
python
chkconfig --add mysqld

(四)显示服务列表
python
chkconfig --list

如果2345是off,则需要执行下列命令:
python
chkconfig --level 2345 mysqld on
(五)重启Linux服务
python
reboot

(六)查看Mysql服务
python
ps -ef | grep mysql

(七)外部工具测试
使用外部连接工具连接Linux上的服务器,能连接成功则证明Mysql完全没有问题!

至此,Mysql安装配置及自启完成!