CentOS 7安装MySQL-Server

1.下载rpm安装包

admin@localhost Downloads]$ wget http://repo.mysql.com/mysql57-communityrelease-el7.rpm
--2020-10-03 11:59:55-- http://repo.mysql.com/mysql57-community-release-el7.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.45.53.26
Connecting to repo.mysql.com (repo.mysql.com)|23.45.53.26|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7.rpm’
100%
[============================================================================>]
25,680 --.-K/s in 0.09s
2020-10-03 11:59:56 (273 KB/s) - ‘mysql57-community-release-el7.rpm’ saved
[25680/25680]
[admin@localhost Downloads]$ ls
mysql57-community-release-el7.rpm
[admin@localhost Downloads]$ ll /etc/yum.repos.d/mysql*
ls: cannot access /etc/yum.repos.d/mysql*: No such file or directory

2.解压安装

[root@localhost Downloads]# rpm -ivh mysql57-community-release-el7.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-11 ################################# [100%]
[root@localhost Downloads]# ll /etc/yum.repos.d/mysql*
-rw-r--r--. 1 root root 1838 Apr 27 2017 /etc/yum.repos.d/mysql-community.repo
-rw-r--r--. 1 root root 1885 Apr 27 2017 /etc/yum.repos.d/mysql-communitysource.rep
[root@localhost Downloads]# yum install mysql-server

3.启动MySQL-Server

sudo su

超户模式下启动mysqld服务: service mysqld start

[root@localhost Downloads]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@localhost Downloads]# netstat -tanp

会有这一行:

tcp6 0 0 :::3306 :::* LISTEN  59808/mysqld

4.登录mysql-server

安装mysql默认生成的密码在log日志文件中:

[root@localhost Downloads]# grep "password" /var/log/mysqld.log
2020-10-03 01:46:39 58097 [Note] Shutting down plugin 'sha256_password'
2020-10-03 01:46:39 58097 [Note] Shutting down plugin 'mysql_old_password'
2020-10-03 01:46:39 58097 [Note] Shutting down plugin 'mysql_native_password'
2020-10-03T04:10:10.401393Z 1 [Note] A temporary password is generated for
root@localhost: fCyQpvz2ao*P
2020-10-03T04:10:17.873968Z 2 [Note] Access denied for user 'root'@'localhost'
(using password: NO)

此时通过上面的密码可首次登录mysql server:

[root@localhost Downloads]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.31
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;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement
before executing this statement.

根据提示必须修改初始密码并重新测试登录:

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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@localhost Downloads]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.31 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>

成功登录

  • 9
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值