1.2二进制安装MySQL5.7

二进制安装MysqL5.7

环境准备

系统:Centos7

软件包: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 -sv 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

[root@centos7 local]# chmod +x /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

[MysqLd]

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

 

!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 etc]cd /usr/local/MysqL

[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                                                                   

LISTEN     0      80                           [::]:3306                                     [::]:*

 

11. 数据库登录查询修改密码退出数据库

[root@centos7 MysqL]#./bin/MysqL -uroot -p

[root@centos7 MysqL]# ./bin/MysqL -uroot -p

Enter password:   root密码为空,直接回车

Welcome to the MysqL monitor.  Commands end with ; or \g.

Your MysqL connection id is 2

Server version: 5.7.30 MysqL Community Server (GPL)

 

copyright (c) 2000, 2021, Oracle and/or its affiliates.

 

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>

 

MysqL> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| MysqL              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)

 

MysqL> use MysqL;

MysqL> SELECT VERSION();

+-----------+

| VERSION() |

+-----------+

| 5.7.30    |

+-----------+

Database changed

 

 

修改用户密码

MysqL> alter user root@'localhost' identified by 'Mmagedu0!';

Query OK, 0 rows affected (0.00 sec)

 

MysqL> grant all privileges on *.* to root@'localhost';

Query OK, 0 rows affected (0.00 sec)

 

MysqL> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

MysqL> exit

Bye

 

12. 登录测试

添加PATH变量才能直接这样敲

[root@centos7 MysqL]#MysqL -uroot -p'Mmagedu0!'

MysqL: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MysqL monitor.  Commands end with ; or \g.

Your MysqL connection id is 3

Server version: 5.7.30 MysqL Community Server (GPL)

 

copyright (c) 2000, 2021, Oracle and/or its affiliates.

 

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>

 

 

 

13. MysqL安全加固

MysqL安装完成后,运行MysqL_secure_installation命令,提高安全性

[root@centos7 MysqL]# 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: y

一路Y下来。

 

相关文章

优化MySQL数据库发布系统存储的方法有:1.mysql库主从读写分...
使用mysql的方法:在“我的电脑”→右键→“管理”→“服务”...
在mysql中查看root用户权限的方法:1.命令行启动mysql服务;...
MySQL主从复制是用来备份一个与主数据库一样环境的从数据库,...
运行mysql的方法1.启动mysql服务,在“我的电脑”→右键→“...
开启mysql的方法1.可以通过快捷键win+r,输入cmd,打开窗口,...