CentOS7.8安装mysql5.7(rpm安装)
一、安装mysql软件
下载MySQL官方的Mysql 5.7.30 的rpm包集合
wget -i -c http://dev.mysql.com/get/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
下载后解压
tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
查看linux上是否已经安装了mysql,有则卸载。
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
安装mysql5.7所需要的依赖
yum install libaio
yum install perl
yum install net-tools
安装mysql
rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm
[[email protected] mysql-5.7.30-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.30-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.30-1.e################################# [100%]
[[email protected] mysql-5.7.30-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.30-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.30-1.el7################################# [100%]
[[email protected] mysql-5.7.30-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-compat-5.7.3################################# [100%]
[[email protected] mysql-5.7.30-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.30-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.30-1.e################################# [100%]
[[email protected] mysql-5.7.30-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.30-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.30-1.e################################# [100%]
二、配置Mysql数据库
启动MySQL
systemctl start mysqld.service
查看MySQL运行状态
systemctl status mysqld.service
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-05-13 12:34:41 HKT; 30s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 11506 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 11446 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 11510 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─11510 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
May 13 12:34:36 CentOS.highning.com systemd[1]: Starting MySQL Server...
May 13 12:34:41 CentOS.highning.com systemd[1]: Started MySQL Server.
找出root初始密码
grep "password" /var/log/mysqld.log
2020-05-13T04:34:38.628340Z 1 [Note] A temporary password is generated for [email protected]: ,/wsw6gif;eH
进入数据库:
mysql -uroot -p
输入密码(密码是上面查询到的 ,/wsw6gif;eH ),此时不能操作数据库,必须修改密码之后才能操作数据库
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功
三、开启mysql的远程访问
执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.0.1,如要开启所有的,用%代替IP):
grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
再输入以下两行命令
flush privileges;
exit
四、为firewalld添加开放端口
添加mysql端口3306和Tomcat端口8080
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
重新载入
firewall-cmd --reload
五、更改mysql的语言
首先重新登录mysql,然后输入status:
[[email protected] Linux]# mysql -uroot -p
Enter password:
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, 2020, 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> status
--------------
mysql Ver 14.14 Distrib 5.7.30, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: [email protected]
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.30 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 21 min 0 sec
Threads: 1 Questions: 14 Slow queries: 0 Opens: 112 Flush tables: 1 Open tables: 105 Queries per second avg: 0.011
--------------
Server characterset: latin1
Db characterset: latin1
这两个不是utf-8
先退出mysql,然后再到/etc目录下的my.cnf文件下修改一下文件内容
加入四行
[client]
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
# 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
character-set-server=utf8
collation-server=utf8_general_ci
# 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
重启下mysql,然后输入status再次查看
[[email protected] Linux]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[[email protected] Linux]# mysql -uroot -p
Enter password:
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, 2020, 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> status
--------------
mysql Ver 14.14 Distrib 5.7.30, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database:
Current user: [email protected]
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.30 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 14 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 105 Flush tables: 1 Open tables: 98 Queries per second avg: 0.357
--------------
最后在windows下用mysql命令登录
Microsoft Windows [版本 10.0.18363.778]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\highning>mysql -h 192.168.88.88 -P 3306 -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.30 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
修改密码安全策略,改为LOW,密码长度最小6位
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 6 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
关于 mysql 密码策略相关参数;
1)、validate_password_length 固定密码的总长度;
2)、validate_password_dictionary_file 指定密码验证的文件路径;
3)、validate_password_mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
4)、validate_password_number_count 整个密码中至少要包含阿拉伯数字的个数;
5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
6)、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;
关于 validate_password_policy 的取值:
LOW:只验证长度;
MEDIUM:验证长度、数字、大小写、特殊字符;
STRONG:验证长度、数字、大小写、特殊字符、字典文件;
推荐阅读
-
CentOS7.8安装mysql5.7(rpm安装)
-
linux jdk的 rpm 方式安装 博客分类: JavaLinux javalinuxjdkrpmrpm -ivh/ rpm -e/ rpm -qa
-
Centos中彻底删除Mysql(rpm、yum安装的情况)
-
Centos中彻底删除Mysql(rpm、yum安装的情况)
-
解决MySQL5.7安装后没有data文件夹无法登录的问题
-
图文详解mysql5.7安装教程
-
通过rpm方式安装Mysql 博客分类: 技术是一种爱好 MySQLLinuxPHP
-
通过rpm方式安装Mysql 博客分类: 技术是一种爱好 MySQLLinuxPHP
-
解决MySQL5.7安装后没有data文件夹无法登录的问题
-
mysql5 rpm linux 安装过程 博客分类: 技术简介 LinuxMySQLCentOSOSAccess