Linux(centos)送到嘴边喂饭式安装MySQL数据库,超级详细

压缩包名:

mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz


本文档结合官方文档以及B站视频教程进行编写。网上 很多文档都是不全的,或者完全没有考虑 过 初学者会出现千奇百怪的错误。安装的时候可以直接复制我的命令,空格太小有人可能看不出来。
官方网站 :

https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html       

//这是官网安装文档的链接,要官方包可以在页面中找
压缩包链接:


hi,这是我用百度网盘分享的内容~复制这段内容打开「百度网盘」APP即可获取
链接:https://pan.baidu.com/s/1lj31b9zlLkbMmkhnPBZu0w
提取码:9ch6

我是在/etc/local/路径下进行解压的,这也是官方 推荐的路径
tar xzvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql_3306
删除系统自带的mariadb,也可以直接删除/etc/my.cnf
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-

//设置用户还有组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
//设置完查看一下
id mysql
//我这里 为了好区分把我解压完的包名变成 了mysql_3306
mv mysql mysql_3306

cd mysql_3306
mkdir mysql-files//用来存放文件

//更改权限
chown mysql:mysql mysql-files
chmod 750 mysql-files

==========================================================

这一步是初始化数据库,生成随机密码才算成功,输入这行命令时会出现好几个[warning],很正常,算是成功
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql_3306
生成一个随机密码:
2021-11-22T15:44:05.339633Z 1 [Note] A temporary password is generated for root@localhost: qy2WC-Eppn)1

解释:

========================================================

--initialize 初始化
--user=mysql  以mysql用户的身份初始化数据库,产生文件都是mysql作为拥有者
--basedir=/usr/local/mysql_3306    mysql其安装目录,非常重要

这时查看mysql目录下是否生成data文件夹,生成了才算成功

===========================================================

//设置安全加密链接
bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql_3306/data


启动MySQL数据库

配置服务
cp support-files/mysql.server /etc/rc.d/init.d/mysql_3306

ll support-files//这个是我个人习惯,查看一下文件里都有什么

vim /etc/rc.d/init.d/mysql_3306//进入到这里,
找到basedir=
datadir=
更改:
===============================

basedir=/usr/local/mysql_3306
datadir=/usr/local/mysql_3306/data

===============================


启动MySQL数据库,不能使用 systemctl

service mysql_3306 start
//当MySQL启动成功后,其日志会自动写入daodata数据目录中的主机名称 .err文件中


设置开机 自启动:

chkconfig -add mysql_3306
chkconfig --add mysql_3306
chkconfig mysql_3306 on

更改数据库管理员密码

ll bin  //有一个mysqladmin
这时输入bin/mysqladmin --help,可以看到相关功能,更改密码之类的
 
netstat -tnlp | grep 3306//输入这个查看进程,看mysql是否启动
===========================================
tcp6       0      0 :::3306                 :::*                    LISTEN      7844/mysqld  
===========================================

输入:
bin/mysqladmin -uroot password '123456' -p//将密码更改为123456,输入完会提示输入密码,这个密码是上面获得的临时密码

输入完临时密码  会出现:
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
没出错,意思是密码太简单了


随后输入:
bin/mysql -uroot -p//然后回车,输入刚刚重新设置 的密码  123456

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

=====配置环境变量======把mysql客户端命令添加到环境变量,以后可以随时访问
echo "export PATH=$PATH:/usr/local/mysql_3306/bin" >>  /etc/profile

随后输入:
source /etc/profile//使环境变量生效,这时直接输入mysql -uroot-p,再输入密码就会直接登录

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


=======手动定义MySQL配置文件(非常重要)=====

vim /mysql_3306/my.cnf

摁 i 输入 :
[mysqld]
basedir=/usr/local/mysql_3306
datadir=/usr/local/mysql_3306/data
socket=/tmp/mysql.sock
如果保存时显示无法打开并写入文件,可以直接touch一个my.cnf再进行写入

配置完要重启
输入:service mysql_3306 restart
显示:Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

======安全配置(对生产环境比较重要)======
 
输入:mysql_secure_installation

显示:
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:
问:是否要安装密码检查器,意思是密码要是123456就不让登录了,得设置一个相当麻烦的

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