二进制安装MySQL5.7

发布时间:2022-12-11 21:00

二进制安装MySQL5.7

环境准备

软件包:mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

1. 安装相关包

[root@centos7 ~]#yum -y install libaio numactl-libs

2. 创建用户和组

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

3. 准备程序文件

[root@centos7 ~]#tar xfv mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@centos7 ~]#cd /usr/local/
[root@centos7 local]#ln -s mysql-5.7.30-linux-glibc2.12-x86_64 mysql
[root@centos7 local]#chown -R mysql.mysql /usr/local/mysql/
[root@centos7 local]#chmod -R 755 /usr/local/mysql/

4. 准备环境变量

[root@centos7 local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos7 local]#. /etc/profile.d/mysql.sh

5. 创建数据库目录,修改权限

[root@centos7 local]#mkdir /data/mysql -pv
mkdir: created directory ‘/data/mysql’
[root@centos7 local]#chown -R mysql:mysql /data/mysql/

6. 准备配置文件

[root@centos7 local]#cd /usr/local/mysql/
[root@centos7 mysql]#cp /etc/my.cnf{,.bak}
[root@centos7 mysql]#vim /etc/my.cnf
[root@centos7 mysql]#cat /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
explicit_defaults_for_timestamp=true
port=3306
character_set_server=utf8
user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/data/mysql/mysql.log
pid-file=/var/run/mariadb/mariadb.pid

[client]
port=3306
socket=/var/lib/mysql/mysql.sock

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

7. 创建配置文件中指定的路径并修改权限

[root@centos7 mysql]#mkdir /var/lib/mysql
[root@centos7 mysql]#chown -R mysql:mysql /var/lib/mysql/
[root@centos7 mysql]#touch /var/lib/mysql/mysql.sock
[root@centos7 mysql]#ll  /var/lib/mysql
total 0
-rw-r--r-- 1 root root 0 Jul 18 23:42 mysql.sock
[root@centos7 mysql]#chmod guo+wr /var/lib/mysql/mysql.sock
[root@centos7 mysql]#ll  /var/lib/mysql
total 0
-rw-rw-rw- 1 root root 0 Jul 18 23:42 mysql.sock
[root@centos7 mysql]#touch /data/mysql/mysql.log
[root@centos7 mysql]#ll /data/mysql/
total 0
-rw-r--r-- 1 root root 0 Jul 18 23:43 mysql.log
[root@centos7 mysql]#chmod guo+rw /data/mysql/mysql.log
[root@centos7 mysql]#ll /data/mysql/mysql.log
-rw-rw-rw- 1 root root 0 Jul 18 23:43 /data/mysql/mysql.log
[root@centos7 mysql]#mkdir /var/run/mariadb
[root@centos7 mysql]#chown -R mysql:mysql /var/run/mariadb/
[root@centos7 mysql]#touch /var/run/mariadb/mariadb.pid
[root@centos7 mysql]#ll /var/run/mariadb/
total 0
-rw-r--r-- 1 root root 0 Jul 18 23:44 mariadb.pid
[root@centos7 mysql]#chmod guo+rw /var/run/mariadb/mariadb.pid
[root@centos7 mysql]#ll /var/run/mariadb/
total 0
-rw-rw-rw- 1 root root 0 Jul 18 23:44 mariadb.pid

8. 初始化数据库文件并生成 root 空密码

[root@centos7 mysql]#rm -rf /data/mysql/*
[root@centos7 mysql]#./bin/mysqld --initialize-insecure --datadir=/data/mysql/ --user=mysql

9 . 启动mysqld守护程序

[root@centos7 mysql]#./bin/mysqld_safe --user=mysql --datadir=/data/mysql &

10. 准备启动脚本,并启动服务

[root@centos7 mysql]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 mysql]#chkconfig --add mysqld
[root@centos7 mysql]#systemctl start mysqld.service
[root@centos7 mysql]#ss -ntl
State      Recv-Q Send-Q              Local Address:Port                             Peer Address:Port
LISTEN     0      128                             *:22                                          *:*
LISTEN     0      100                     127.0.0.1:25                                          *:*
LISTEN     0      128                          [::]:22                                       [::]:*
LISTEN     0      100                         [::1]:25                                       [::]:*
LISTEN     0      80                           [::]:3306                                     [::]:*

11. 数据库的登录、查询,修改密码,Ctrl+D,退出数据库

[root@centos7 mysql]#./bin/mysql -uroot -p
Enter password:  #root密码为空,直接回车
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
mysql> use mysql;
mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.30    |
+-----------+
mysql> alter user root@'localhost' identified by 'MySQL@2022.';
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit

12. 登录测试

[root@centos7 mysql]#mysql -uroot -pMySQL@2022.

13. MySQL安全加固

在MySQL安装完成后,运行mysql_secure_installation命令,提高安全性

[root@centos7 mysql]#mysql_secure_installation
Securing the MySQL server deployment.

Enter password for user root:  #输入root用户的当前密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n  #已经设置好密码了,不用改,回答“n”


 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  #删除匿名用户,回答“y”
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  #删除test数据库,回答“y”
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y  #重新加载特权表,回答“y”
Success.

All done!

相关推荐

SSL Certificate Signed Using Weak Hashing Algorithm(CVE-2004-2761)

以太坊之Ubuntu平台DApp开发环境的搭建

c语言常见的字符函数,(C语言)常见字符函数和字符串函数

Kafka 延时队列&重试队列

Lab: File path traversal, traversal sequences stripped non-recursively 文件路径遍历,遍历非递归过滤的语句

写Python爬虫又被屏蔽了,你现在需要一个稳定的代理IP

操作系统复习知识点(第三章)

【可视化分析案例】用python分析B站Top100排行榜数据

韩顺平 java 坦克大战_Tankgame 韩顺平版本的坦克大战,详细包括源代码,素材以及对应文件 Java Develop 263万源代码下载- www.pudn.com...

工作流引擎在vivo营销自动化中的应用实践 | 引擎篇03

STM32超声波避障小车(stm32f103c8t6/HAL/舵机云台+超声波)

理解NLP迁移学习/Transformers/GPT/Bert中遇到的难点和笔记

DGL笔记3——自己写一个GNN模型

高斯过程相关研究的新进展的8篇论文推荐(统计 +人工智能)

Java程序员必备!俄罗斯方块java通用版下载

C++中sort函数从大到小排序的两种方法

华为harmonyOS鸿蒙怎么读,了解HarmonyOS是如何形成独特字体系统!荣耀系列鸿蒙OS下月来?...

深入切尔诺贝利禁区,波士顿动力机器狗执行测试任务-1

飞桨创意赛火热进行中,总有一款AI时代Chatbot适合你

数学建模算法与应用:预测模型(3)案例: SARS 疫情对经济指标影响

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号