CentOS 7 利用yum源安装MySQL5.7

# 配置yum源文件
[root@centos79-mysql01 ~]# vim /etc/yum.repos.d/mysql.repo
[mysql]
name=mysql5.7
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
gpgcheck=0
enable=1

[root@centos79-mysql01 ~]# yum clean all
[root@centos79-mysql01 ~]# yum makecache

# yum安装mysql
[root@centos79-mysql01 ~]# yum install -y mysql-community-server.x86_64

# 启动mysqld并设置开机自启
[root@centos79-mysql01 ~]# systemctl enable --now mysqld

# 查看初始密码
[root@centos79-mysql01 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@centos79-mysql01 ~]# grep password /var/log/mysqld.log
2022-11-15T07:54:22.330484Z 1 [Note] A temporary password is generated for root@localhost: DffYA=L62T08
2022-11-15T07:54:55.207477Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

# 使用初始密码登录数据库无法执行操作,需要修改密码才行
[root@centos79-mysql01 ~]# mysql -uroot -p'DffYA=L62T08'
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.40
Copyright (c) 2000, 2022, 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> status
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

# 修改密码,新密码需要具有复杂性要求
mysql> alter user root@'localhost' identified by '1qaz@WSX';
Query OK, 0 rows affected (0.00 sec)


# 使用新密码登录数据库,并执行操作
[root@centos79-mysql01 ~]# mysql -uroot -p'1qaz@WSX'
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 4
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> status
--------------
mysql  Ver 14.14 Distrib 5.7.40, for Linux (x86_64) using  EditLine wrapper

Connection id:		4
Current database:
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.40 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:			4 min 11 sec

Threads: 1  Questions: 10  Slow queries: 0  Opens: 107  Flush tables: 1  Open tables: 100  Queries per second avg: 0.039
--------------
# 其他修改密码的方法
[root@centos79-mysql01 ~]# mysqladmin -uroot -p'1qaz@WSX' password 'Root123!'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@centos79-mysql01 ~]# mysql -uroot -p'Root123!'
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 9
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> status
--------------
mysql  Ver 14.14 Distrib 5.7.40, for Linux (x86_64) using  EditLine wrapper

Connection id:		9
Current database:
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.40 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:			6 min 49 sec

Threads: 1  Questions: 26  Slow queries: 0  Opens: 110  Flush tables: 1  Open tables: 103  Queries per second avg: 0.063
-------------- 
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享