1.2二进制安装MySQL5.7

2022/7/31 2:52:46

本文主要是介绍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下来。

 



这篇关于1.2二进制安装MySQL5.7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程