YUM安装MYSQL8.0.35

#查询系统是否安装有mariadb
[root@localhost ~]# rpm -qa | grep mariadb
强制卸载旧版
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
#安装mysql80
[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# yum -y install mysql80-community-release-el7-3.noarch.rpm 
#运行如下命令安装GPG,如果不安装执行yum安装mysql会出现错误
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# systemctl start mysqld
#查看是否安装
[root@localhost ~]# ps -ef | grep mysql
mysql       976      1  1 Dec10 ?        00:23:26 /usr/sbin/mysqld
root      74340  73803  0 09:12 pts/0    00:00:00 grep --color=auto mysql
[root@localhost ~]# 
#查看端口
[root@localhost ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      7866/php-fpm: maste 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      906/sshd            
tcp6       0      0 :::443                  :::*                    LISTEN      28344/httpd         
tcp6       0      0 :::33060                :::*                    LISTEN      976/mysqld          
tcp6       0      0 :::3306                 :::*                    LISTEN      976/mysqld          
tcp6       0      0 :::80                   :::*                    LISTEN      28344/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      906/sshd            
[root@localhost ~]# 

#查看默认密码:
[root@appserver ~]# cat /var/log/mysqld.log | grep password 
#使用查到的密码登录mysql,再个修改密码
[root@appserver ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5972
Server version: 8.0.35 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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.

#配置文件
[root@appserver ~]# find / -name my.cnf
/etc/my.cnf
[root@appserver ~]# 
#如果密码输入不对,无法登录,可能使用skipe-grant-tables来跳过密码登录,修改密码。方法:my.cnf配置文件[mysqld]增加skip-grant-tables
[root@appserver ~]# vim /etc/my.cnf

#重启服务
[root@localhost ~]# systemctl restart mysqld
#登录mysql,跳过验证,无密码登录msyql
[root@localhost ~]# mysql -uroot -p 
#清空mysql root账号密码
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> 

mysql> UPDATE user SET authentication_string="" WHERE user="root";
Query OK, 1 row affected (0.11 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> 

mysql> flush priveleges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'priveleges' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

#确认密码是否清空
mysql> select user,authentication_string from user where user='root';
+------+-----------------------+
| user | authentication_string |
+------+-----------------------+
| root |                       |
+------+-----------------------+
1 row in set (0.00 sec)
mysql> 

#退出MySQL,去掉配置文件skip-grant-tables,重新MySQL服务
mysql> quit
Bye
[root@appserver ~]# vim /etc/my.cnf
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# 

#再次无密码登录mysql,设定新密码
mysql> alter user 'root'@'localhost' identified by 'admin@123#@456'; 
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> 

#提示新密码不符合密码要求。
#查看密码复杂性要求表
mysql> show variables like 'validate_password%'; 
+-------------------------------------------------+--------+
| Variable_name                                   | Value  |
+-------------------------------------------------+--------+
| validate_password.changed_characters_percentage | 0      |
| validate_password.check_user_name               | ON     |
| 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      |
+-------------------------------------------------+--------+
8 rows in set (0.01 sec)

mysql> 
#降低mysql密码复杂性
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> 
#再次个修改密码

mysql> alter user 'root'@'localhost' identified by 'admin@123';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
mysql> 

#报1396错误
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> select use,host from user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use,host from user' at line 1
mysql> select user ,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| nextcloud        | %         |
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| nextcloud        | localhost |
+------------------+-----------+
6 rows in set (0.01 sec)

mysql> 
#可以看到,root的host是%,而修改的密码是localhsot
#再次修改密码:

mysql> alter user 'root'@'%' identified by 'admin@123';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿蔡BLOG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值