Centos7-MySQL5.7.16配置
安装包准备
安装包准备,将准备好的安装包和驱动上传到linux,共计6个。
[hadoop@hd1 mysql5]$ du -sh *
272K 01_mysql-community-common-5.7.16-1.el7.x86_64.rpm
2.2M 02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm
2.1M 03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
24M 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm
152M 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm
852K mysql-connector-java-5.1.27-bin.jar
卸载Centos7自带的MySQL/Mariadb
# 卸载系统自动的MySQL/Mariadb
[hadoop@hd1 mysql5]$ rpm -qa | grep -i -E mysql\|mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[hadoop@hd1 mysql5]$ rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps
[hadoop@hd1 mysql5]$ rpm -qa | grep -i -E mysql\|mariadb
[hadoop@hd1 mysql5]$
# 安装MySQL5.7.16
[hadoop@hd1 mysql5]$ sudo rpm -ivh 01_mysql-community-common-5.7.16-1.el7.x86_64.rpm
warning: 01_mysql-community-common-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.16-1.e################################# [100%]
[hadoop@hd1 mysql5]$ sudo rpm -ivh 02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm
warning: 02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.16-1.el7################################# [100%]
[hadoop@hd1 mysql5]$ sudo rpm -ivh 03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
warning: 03_mysql-community-libs-compat-5.7.16-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.1################################# [100%]
[hadoop@hd1 mysql5]$ sudo rpm -ivh 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm
warning: 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.16-1.e################################# [100%]
[hadoop@hd1 mysql5]$ sudo rpm -ivh 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm
warning: 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.16-1.e################################# [100%]
- rpm -qa 列出rpm方式安装的软件
- grep -i -E 筛选出所需的软件
- xargs -n1 安装一个一个的方式执行命令
- rpm -e –nodeps 卸载软件,不考虑依赖问题
安装MySQL遇到错误处理方法在其尾部添加命令--force --nodeps
sudo rpm -ivh 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm –force –nodeps
返回目录
配置MySQL
# 启动mysql
sudo systemctl start mysqld
# 查看MySQL密码
sudo cat /var/log/mysqld.log | grep password
# 配置MySQL
mysql -uroot -p
# 调弱密码策略
set global validate_password_length=4;
set global validate_password_policy=0;
# 更新mysql root账号的密码
set password=password("2022");
# 创建hive账号
create user 'hive'@'%' identified by '123456';
grant all on *.* to 'hive'@'%';
flush privileges;
# mysql开机自启
sudo systemctl enable mysqld
操作记录
[hadoop@hd1 mysql5]$ sudo systemctl start mysqld
[hadoop@hd1 mysql5]$ sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-11-08 02:16:06 CST; 18s ago
Process: 5493 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 5419 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 5496 (mysqld)
CGroup: /system.slice/mysqld.service
└─5496 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 08 02:15:57 hd1.pblh123.cn systemd[1]: Starting MySQL Server...
Nov 08 02:16:06 hd1.pblh123.cn systemd[1]: Started MySQL Server.
[hadoop@hd1 mysql5]$ sudo cat /var/log/mysqld.log | grep password
2022-11-07T18:15:58.466037Z 1 [Note] A temporary password is generated for root@localhost: 9COd-dl,gDTy
[hadoop@hd1 mysql5]$ 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.16
Copyright (c) 2000, 2016, 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> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set password=password("2022");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create user 'hive'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to 'hive'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
远程连接测试
版权声明:本文为pblh123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。