Linux安装MySQL

[root@iZuf6j83unak4htk3braolZ opt]# rpm -qa | grep mysql  #查看是否已安装MySQL,无输出证明未安装

首先下载 yum 资源包,地址 MySQL :: Download MySQL Yum Repository

        

[root@iZuf6j83unak4htk3braolZ opt]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm  #下载 yum 资源包
[root@iZuf6j83unak4htk3braolZ opt]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
[root@iZuf6j83unak4htk3braolZ opt]# yum update  #更新
[root@iZuf6j83unak4htk3braolZ opt]# yum install mysql-server  #安装 mysql-server
[root@iZuf6j83unak4htk3braolZ opt]# mysqld --initialize  #初始化
[root@iZuf6j83unak4htk3braolZ opt]# chown mysql:mysql -R /var/lib/mysql  #配置权限
[root@iZuf6j83unak4htk3braolZ opt]# systemctl start mysqld  #启动服务
[root@iZuf6j83unak4htk3braolZ opt]# systemctl status mysqld  #查看服务状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-17 16:50:42 CST; 12s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 23720 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 23743 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 12399)
Memory: 362.2M
CGroup: /system.slice/mysqld.service
└─23743 /usr/sbin/mysqld

Aug 17 16:50:40 iZuf6j83unak4htk3braolZ systemd[1]: Starting MySQL Server...
Aug 17 16:50:42 iZuf6j83unak4htk3braolZ systemd[1]: Started MySQL Server.

 查看 MySQL 安装默认密码

[root@iZuf6j83unak4htk3braolZ /]# grep "password" /var/log/mysqld.log
2021-08-17T08:48:13.097011Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: e!.&WSzp_2hB

进入 MySQL 

[root@iZuf6j83unak4htk3braolZ /]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.26

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

修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

ok,到此已经完成!

设置允许远程连接,进入MySQL中执行如下命令

update user set host = '%' where user = 'root';

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值