Linux本地安装MySQL 5.7.34数据库

下载MySQL安装包,官网下载地址:https://dev.mysql.com/downloads/mysql/

百度网盘地址:

5.7.31:

链接:https://pan.baidu.com/s/1KakWddXmm6ePZudzmNMC3Q
提取码:2021

5.4.34:

链接:https://pan.baidu.com/s/1J4lhPOfQq5ITJlC9wEeCqg
提取码:2021

下载完成后将rpm包上传至服务器

查看防火墙状态并开放防火墙端口

[root@test-220 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 二 2021-10-12 14:12:22 CST; 5 days ago
     Docs: man:firewalld(1)
 Main PID: 1164 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─1164 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

10月 12 14:12:22 test-220 systemd[1]: Starting firewalld - dynamic firewall daemon...
10月 12 14:12:22 test-220 systemd[1]: Started firewalld - dynamic firewall daemon.
[root@test-220 ~]# firewall-cmd --list-ports

[root@test-220 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@test-220 ~]# firewall-cmd  --reload
success
[root@test-220 ~]# firewall-cmd --list-ports
3306/tcp
[root@test-220 ~]#

安装MySQL数据库

[root@mysql-220 ~]# cd /opt/app/
[root@mysql-220 ~]# ll 
总用量 529384
drwxr-xr-x. 2 root root       129 10月 22 22:16 getpack
drwxr-xr-x. 2 root root        62 10月 22 22:16 java
-rw-r--r--. 1 root root 542072471 10月 25 09:54 mysql-community-5.7.34-1.el7.x86_64.tar.gz
drwxr-xr-x. 2 root root     12288 10月 22 22:15 tools
[root@mysql-220 app]# tar zxvf mysql-community-5.7.34-1.el7.x86_64.tar.gz
mysql-community-5.7.34-1.el7.x86_64/mysql-community-client-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-common-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-embedded-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-embedded-compat-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-embedded-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-libs-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-server-5.7.34-1.el7.x86_64.rpm
mysql-community-5.7.34-1.el7.x86_64/mysql-community-test-5.7.34-1.el7.x86_64.rpm
[root@mysql-220 app]# rpm -Uvh mysql-community-5.7.34-1.el7.x86_64/*.rpm --nodeps --force
警告:mysql-community-5.7.34-1.el7.x86_64/mysql-community-client-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.34-1.e################################# [  9%]
   2:mysql-community-libs-5.7.34-1.el7################################# [ 18%]
   3:mysql-community-client-5.7.34-1.e################################# [ 27%]
   4:mysql-community-server-5.7.34-1.e################################# [ 36%]
   5:mysql-community-devel-5.7.34-1.el################################# [ 45%]
   6:mysql-community-embedded-5.7.34-1################################# [ 55%]
   7:mysql-community-embedded-devel-5.################################# [ 64%]
   8:mysql-community-test-5.7.34-1.el7################################# [ 73%]
   9:mysql-community-libs-compat-5.7.3################################# [ 82%]
  10:mysql-community-embedded-compat-5################################# [ 91%]
正在清理/删除...
  11:mariadb-libs-1:5.5.65-1.el7      ################################# [100%]

 

 启动MySQL服务并设置开机自启

[root@test-220 mysql-5.7.34-1.el7.x86_64]# systemctl enable mysqld
[root@test-220 mysql-5.7.34-1.el7.x86_64]# systemctl start mysqld

查看mysql初始密码并登陆数据库

[root@test-220 mysql-5.7.34-1.el7.x86_64]# grep 'password' /var/log/mysqld.log
2021-10-18T04:59:55.409832Z 1 [Note] A temporary password is generated for root@localhost: X9Rkq>WvwIsM
[root@test-220 mysql-5.7.34-1.el7.x86_64]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

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> alter user root@"localhost" identified by 'Voice@123';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

查看密码策略

mysql> show variables like '%validate_password_policy%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| validate_password_policy | MEDIUM |
+--------------------------+--------+
1 row in set (0.00 sec)

mysql> show variables like '%validate_password_length%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| validate_password_length | 8     |
+--------------------------+-------+
1 row in set (0.01 sec)

mysql>

修改密码策略、查看并验证

1、SQL语句修改密码策略并测试修改密码:

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%validate_password_policy%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| validate_password_policy | LOW   |
+--------------------------+-------+
1 row in set (0.01 sec)

mysql> show variables like '%validate_password_length%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| validate_password_length | 4     |
+--------------------------+-------+
1 row in set (0.00 sec)
mysql> alter user 'root'@'localhost' identified by 'voicecyber';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

 

2、配置文件修改:

vim /etc/my.cnf在“[mysql]”下面添加下面最后两行:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid



validate_password_policy=0
validate_password=off

保存退出,重启服务

修改默认字符编码为UTF-8

vim /etc/my.cnf 在文件里面添加以下内容:

[mysqld]
character-set-server=utf8
lower_case_table_names=1

validate_password_policy=0
validate_password=off

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8 

保存退出并重启服务

 

开启MySQL远程权限

[root@test-220 mysql-5.7.34-1.el7.x86_64]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> grant all privileges on *.* to 'root'@'%' identified by 'voicecyber' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

 

重启MySQL服务

 

[root@test-220 mysql-5.7.34-1.el7.x86_64]# systemctl restart mysqld
[root@test-220 mysql-5.7.34-1.el7.x86_64]#

查看MySQL服务进程以及端口号

[root@test-220 mysql-5.7.34-1.el7.x86_64]# ps -aux|grep mysql
mysql      2636  0.3  2.1 1121272 174848 ?      Sl   13:18   0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root       2665  0.0  0.0 112824   984 pts/0    S+   13:20   0:00 grep --color=auto mysql
[root@test-220 mysql-5.7.34-1.el7.x86_64]# netstat -anlpt|grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      2636/mysqld    
[root@test-220 mysql-5.7.34-1.el7.x86_64]#

本地安装MySQL数据库完成

卸载MySQL:

test-222:/opt # rpm -qa|grep mysql
mysql-community-libs-5.7.34-1.sles12.x86_64
mysql-community-devel-5.7.34-1.sles12.x86_64
mysql-community-server-5.7.34-1.sles12.x86_64
mysql-community-common-5.7.34-1.sles12.x86_64
mysql-community-client-5.7.34-1.sles12.x86_64
test-222:/opt # rpm -qa|grep mysql|xargs -i rpm --nodeps -e {}
test-222:/opt # rpm -qa|grep mysql

 

posted @ 2021-10-18 13:19  叶宇梵  阅读(330)  评论(0)    收藏  举报